Skip to content

Commit d9fa8a3

Browse files
bavulapatijviotti
andauthored
style(clang-tidy): fix bugprone-return-const-ref-from-parameter errors (sourcemeta#1732)
Fixes sourcemeta#1657 Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com> Signed-off-by: Juan Cruz Viotti <jv@jviotti.com> Co-authored-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 74fdf81 commit d9fa8a3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/core/jsonpointer/include/sourcemeta/core/jsonpointer.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ using PointerTemplate = GenericPointerTemplate<Pointer>;
7474
SOURCEMETA_CORE_JSONPOINTER_EXPORT
7575
auto get(const JSON &document, const Pointer &pointer) -> const JSON &;
7676

77+
// Constant reference parameters can accept xvalues which will be destructed
78+
// after the call. When the function returns such a parameter also as constant
79+
// reference, then the returned reference can be used after the object it refers
80+
// to has been destroyed.
81+
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
82+
// This overload avoids mis-uses of retuning const reference parameter as
83+
// constant reference.
84+
auto get(JSON &&document, const Pointer &pointer) -> const JSON & = delete;
85+
7786
/// @ingroup jsonpointer
7887
/// Get a value from a JSON document using a JSON WeakPointer (`const`
7988
/// overload).
@@ -98,6 +107,15 @@ auto get(const JSON &document, const Pointer &pointer) -> const JSON &;
98107
SOURCEMETA_CORE_JSONPOINTER_EXPORT
99108
auto get(const JSON &document, const WeakPointer &pointer) -> const JSON &;
100109

110+
// Constant reference parameters can accept xvalues which will be destructed
111+
// after the call. When the function returns such a parameter also as constant
112+
// reference, then the returned reference can be used after the object it refers
113+
// to has been destroyed.
114+
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
115+
// This overload avoids mis-uses of retuning const reference parameter as
116+
// constant reference.
117+
auto get(JSON &&document, const WeakPointer &pointer) -> const JSON & = delete;
118+
101119
/// @ingroup jsonpointer
102120
/// Get a value from a JSON document using a Pointer, returning an optional that
103121
/// is not set if the path does not exist in the document. For example:

0 commit comments

Comments
 (0)