Enhance return-stack-address check (in Sema) to handle fields that themselves are references.  (Fixes PR 7999; fix by Chandler Carruth).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112792 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaCXX/return-stack-addr.cpp b/test/SemaCXX/return-stack-addr.cpp
index ba64765..7d4cb96 100644
--- a/test/SemaCXX/return-stack-addr.cpp
+++ b/test/SemaCXX/return-stack-addr.cpp
@@ -108,5 +108,16 @@
   return const_cast<int*>(&x);  // expected-warning {{address of stack memory}}
 }
 
+// PR 7999 - handle the case where a field is itself a reference.
+template <typename T> struct PR7999 {
+  PR7999(T& t) : value(t) {}
+  T& value;
+};
+
+struct PR7999_X {};
+
+PR7999_X& PR7999_f(PR7999<PR7999_X> s) { return s.value; } // no-warning
+void test_PR7999(PR7999_X& x) { (void)PR7999_f(x); } // no-warning
+
 // TODO: test case for dynamic_cast.  clang does not yet have
 // support for C++ classes to write such a test case.