@@ -74,6 +74,15 @@ using PointerTemplate = GenericPointerTemplate<Pointer>;
74
74
SOURCEMETA_CORE_JSONPOINTER_EXPORT
75
75
auto get (const JSON &document, const Pointer &pointer) -> const JSON &;
76
76
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
+
77
86
// / @ingroup jsonpointer
78
87
// / Get a value from a JSON document using a JSON WeakPointer (`const`
79
88
// / overload).
@@ -98,6 +107,15 @@ auto get(const JSON &document, const Pointer &pointer) -> const JSON &;
98
107
SOURCEMETA_CORE_JSONPOINTER_EXPORT
99
108
auto get (const JSON &document, const WeakPointer &pointer) -> const JSON &;
100
109
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
+
101
119
// / @ingroup jsonpointer
102
120
// / Get a value from a JSON document using a Pointer, returning an optional that
103
121
// / is not set if the path does not exist in the document. For example:
0 commit comments