re PR c++/26671 (Missing "warning: reference to local variable returned")

PR c++/26671
        * typeck.c (maybe_warn_about_returning_address_of_local): Look
        through COMPONENT_REF and ARRAY_REF.

From-SVN: r116714
This commit is contained in:
Jason Merrill 2006-09-06 01:25:29 -04:00 committed by Jason Merrill
parent 2635450a7f
commit a1a9524971
3 changed files with 29 additions and 0 deletions

View 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.

View 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)

View File

@ -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];
}