From 3a6f62dc34a761303dca80ef314032e565aee7d8 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 24 Jun 2025 11:29:06 +0530 Subject: [PATCH 1/2] style(clang-tidy): fix `bugprone-return-const-ref-from-parameter` Reported with #1754 Refs #1657 Signed-off-by: Balakrishna Avulapati --- src/core/json/include/sourcemeta/core/json_value.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/json/include/sourcemeta/core/json_value.h b/src/core/json/include/sourcemeta/core/json_value.h index 8c21ec6fd..d63581c65 100644 --- a/src/core/json/include/sourcemeta/core/json_value.h +++ b/src/core/json/include/sourcemeta/core/json_value.h @@ -798,6 +798,16 @@ 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: From eb6d290cc97e5052e334368ae7cbd524ff2bf70e Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 24 Jun 2025 20:48:46 +0530 Subject: [PATCH 2/2] Add whitespace for consistency Signed-off-by: Balakrishna Avulapati --- src/core/json/include/sourcemeta/core/json_value.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/json/include/sourcemeta/core/json_value.h b/src/core/json/include/sourcemeta/core/json_value.h index d63581c65..4f1527a77 100644 --- a/src/core/json/include/sourcemeta/core/json_value.h +++ b/src/core/json/include/sourcemeta/core/json_value.h @@ -808,6 +808,7 @@ class SOURCEMETA_CORE_JSON_EXPORT JSON { [[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: