Skip to content

Commit 14c16b0

Browse files
authored
style(clang-tidy): fix bugprone-return-const-ref-from-parameter (#1759)
Reported with #1754 Refs #1657 Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
1 parent 305909d commit 14c16b0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/core/json/include/sourcemeta/core/json_value.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,17 @@ class SOURCEMETA_CORE_JSON_EXPORT JSON {
798798
const typename Object::Container::hash_type hash,
799799
const JSON &otherwise) const -> const JSON &;
800800

801+
// Constant reference parameters can accept xvalues which will be destructed
802+
// after the call. When the function returns such a parameter also as constant
803+
// reference, then the returned reference can be used after the object it
804+
// refers to has been destroyed.
805+
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
806+
// This overload avoids mis-uses of retuning const reference parameter as
807+
// constant reference.
808+
[[nodiscard]] auto at_or(const String &key,
809+
const typename Object::Container::hash_type hash,
810+
JSON &&otherwise) const -> const JSON & = delete;
811+
801812
/// This method retrieves a reference to the first element of a JSON array.
802813
/// This method is undefined if the input JSON instance is an empty array. For
803814
/// example:

0 commit comments

Comments
 (0)