re PR c++/63203 (Self-initialization of reference not diagnosed if it occurs within a loop)

/cp
2014-11-24  Jonathan Wakely  <jwakely@redhat.com>
	    Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/63203
	* decl.c (initialize_local_var): Add -Winit-self warning for
	references initialized with themselves.

/testsuite
2014-11-24  Jonathan Wakely  <jwakely@redhat.com>
	    Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/63203
	* g++.dg/warn/Winit-self-2.C: New.

Co-Authored-By: Paolo Carlini <paolo.carlini@oracle.com>

From-SVN: r218017
This commit is contained in:
Jonathan Wakely 2014-11-24 13:35:08 +00:00 committed by Paolo Carlini
parent f9b1eec215
commit 8be2ce257e
4 changed files with 38 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2014-11-24 Jonathan Wakely <jwakely@redhat.com>
Paolo Carlini <paolo.carlini@oracle.com>
PR c++/63203
* decl.c (initialize_local_var): Add -Winit-self warning for
references initialized with themselves.
2014-11-24 Jason Merrill <jason@redhat.com>
PR c++/63942

View File

@ -6132,13 +6132,23 @@ initialize_local_var (tree decl, tree init)
/* Perform the initialization. */
if (init)
{
if (TREE_CODE (init) == INIT_EXPR
&& !TREE_SIDE_EFFECTS (TREE_OPERAND (init, 1)))
tree rinit = (TREE_CODE (init) == INIT_EXPR
? TREE_OPERAND (init, 1) : NULL_TREE);
if (rinit && !TREE_SIDE_EFFECTS (rinit))
{
/* Stick simple initializers in DECL_INITIAL so that
-Wno-init-self works (c++/34772). */
gcc_assert (TREE_OPERAND (init, 0) == decl);
DECL_INITIAL (decl) = TREE_OPERAND (init, 1);
DECL_INITIAL (decl) = rinit;
if (warn_init_self && TREE_CODE (type) == REFERENCE_TYPE)
{
STRIP_NOPS (rinit);
if (rinit == decl)
warning_at (DECL_SOURCE_LOCATION (decl),
OPT_Winit_self,
"reference %qD is initialized with itself", decl);
}
}
else
{

View File

@ -1,3 +1,9 @@
2014-11-24 Jonathan Wakely <jwakely@redhat.com>
Paolo Carlini <paolo.carlini@oracle.com>
PR c++/63203
* g++.dg/warn/Winit-self-2.C: New.
2014-11-24 Petr Murzin <petr.murzin@intel.com>
* gcc.target/i386/extract-insert-combining.c: New test.

View File

@ -0,0 +1,12 @@
// PR c++/63203
// { dg-options "-Winit-self" }
struct string { };
int main()
{
for (int ii = 0; ii < 1; ++ii)
{
const string& str = str; // { dg-warning "is initialized with itself" }
}
}