PR c++/26671
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Sep 2006 05:25:29 +0000 (05:25 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Sep 2006 05:25:29 +0000 (05:25 +0000)
        * typeck.c (maybe_warn_about_returning_address_of_local): Look
        through COMPONENT_REF and ARRAY_REF.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116714 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/g++.dg/warn/return-reference2.C [new file with mode: 0644]

index 3b53412..014c76b 100644 (file)
@@ -1,5 +1,9 @@
 2006-09-05  Jason Merrill  <jason@redhat.com>
 
+       PR c++/26671
+       * typeck.c (maybe_warn_about_returning_address_of_local): Look 
+       through COMPONENT_REF and ARRAY_REF.    
+
        PR c++/26102
        * name-lookup.c (do_class_using_decl): Try to find the base even
        if bases_dependent_p.
index c07a78d..220be7e 100644 (file)
@@ -6365,6 +6365,10 @@ maybe_warn_about_returning_address_of_local (tree retval)
        }
     }
 
+  while (TREE_CODE (whats_returned) == COMPONENT_REF
+        || TREE_CODE (whats_returned) == ARRAY_REF)
+    whats_returned = TREE_OPERAND (whats_returned, 0);
+
   if (DECL_P (whats_returned)
       && DECL_NAME (whats_returned)
       && DECL_FUNCTION_SCOPE_P (whats_returned)
diff --git a/gcc/testsuite/g++.dg/warn/return-reference2.C b/gcc/testsuite/g++.dg/warn/return-reference2.C
new file mode 100644 (file)
index 0000000..96e44a1
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/26671
+
+class A
+{
+public:
+  int first;
+  int second;
+
+};
+
+int &f()
+{
+  A a;                         // { dg-error "local" }
+  return a.second;
+}
+
+int &g()
+{
+  int ar[42];                  // { dg-error "local" }
+  return ar[20];
+}