Skip to content

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

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 all 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
11 changes: 11 additions & 0 deletions src/core/json/include/sourcemeta/core/json_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,17 @@ class SOURCEMETA_CORE_JSON_EXPORT JSON {
const typename Object::Container::hash_type hash,
const JSON &otherwise) const -> const JSON &;

// 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.
[[nodiscard]] auto at_or(const String &key,
const typename Object::Container::hash_type hash,
JSON &&otherwise) const -> const JSON & = delete;

/// This method retrieves a reference to the first element of a JSON array.
/// This method is undefined if the input JSON instance is an empty array. For
/// example:
Expand Down