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:
parent
2635450a7f
commit
a1a9524971
@ -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.
|
||||
|
@ -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)
|
||||
|
21
gcc/testsuite/g++.dg/warn/return-reference2.C
Normal file
21
gcc/testsuite/g++.dg/warn/return-reference2.C
Normal 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];
|
||||
}
|
Loading…
Reference in New Issue
Block a user