Skip to content

style(clang-tidy): fix bugprone-return-const-ref-from-parameter errors #1732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/core/jsonpointer/include/sourcemeta/core/jsonpointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ using PointerTemplate = GenericPointerTemplate<Pointer>;
SOURCEMETA_CORE_JSONPOINTER_EXPORT
auto get(const JSON &document, const Pointer &pointer) -> const JSON &;

// overloaded function
// Constant reference parameters can accept xvalues which will be destructed
// after the call. When the function returns such a parameter also as constant
// reference, then the returned reference can be used after the object it refers
// to has been destroyed.
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
// This overload avoids mis-uses of retuning const reference parameter as
// constant reference.
auto get(JSON &&document, const Pointer &pointer) -> const JSON & = delete;

/// @ingroup jsonpointer
/// Get a value from a JSON document using a JSON WeakPointer (`const`
/// overload).
Expand All @@ -98,6 +108,16 @@ auto get(const JSON &document, const Pointer &pointer) -> const JSON &;
SOURCEMETA_CORE_JSONPOINTER_EXPORT
auto get(const JSON &document, const WeakPointer &pointer) -> const JSON &;

// overloaded function
// Constant reference parameters can accept xvalues which will be destructed
// after the call. When the function returns such a parameter also as constant
// reference, then the returned reference can be used after the object it refers
// to has been destroyed.
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
// This overload avoids mis-uses of retuning const reference parameter as
// constant reference.
auto get(JSON &&document, const WeakPointer &pointer) -> const JSON & = delete;

/// @ingroup jsonpointer
/// Get a value from a JSON document using a Pointer, returning an optional that
/// is not set if the path does not exist in the document. For example:
Expand Down