================
@@ -539,11 +578,28 @@ int* return_pointer_to_parameter(int a) {
                 // expected-note@-1 {{returned here}}
 }
 
-const int& return_reference_to_parameter(int a)
-{
-    const int &b = a; 
-    return b;         // expected-warning {{address of stack memory is 
returned later}}
-                      // expected-note@-1 {{returned here}}
+const int& return_reference_to_parameter(int a) {
+    const int &b = a;   // expected-warning {{address of stack memory is 
returned later}}
+    return b;           // expected-note {{returned here}}
+}
+int return_reference_to_parameter_no_error(int a) {
+    const int &b = a;
+    return b;
+}
+
+const int& reference_via_conditional(int a, int b, bool cond) {
+    const int &c = (cond ? ((a)) : (b));  // expected-warning 2 {{address of 
stack memory is returned later}}
+    return c;                             // expected-note 2 {{returned here}}
+}
+const int* return_pointer_to_parameter_via_reference(int a, int b, bool cond) {
+    const int &c = cond ? a : b;  // expected-warning 2 {{address of stack 
memory is returned later}}
+    const int* d = &c;
+    return d;                     // expected-note 2 {{returned here}}
+}
+// FIXME: Dereference of a pointer does not track the reference.
----------------
usx95 wrote:

This is done in a followup PR.

https://github.com/llvm/llvm-project/pull/168344
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to