re PR c++/56100 (spurious -Wshadow warning with local variable in template class)

/cp
2015-04-01  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/56100
	* pt.c (instantiating_current_function_p): New.
	* name-lookup.c (pushdecl_maybe_friend_1): Use it.
	* cp-tree.h (instantiating_current_function_p): Declare.

/testsuite
2015-04-01  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/56100
	* g++.dg/warn/Wshadow-8.C: New.
	* g++.dg/warn/Wshadow-9.C: Likewise.
	* g++.dg/warn/Wshadow-10.C: Likewise.
	* g++.dg/warn/Wshadow-11.C: Likewise.

From-SVN: r221814
This commit is contained in:
Paolo Carlini 2015-04-01 21:27:55 +00:00 committed by Paolo Carlini
parent 35238bb505
commit b4d5e41f1d
8 changed files with 83 additions and 4 deletions

View File

@ -5732,6 +5732,7 @@ extern tree get_mostly_instantiated_function_type (tree);
extern bool problematic_instantiation_changed (void); extern bool problematic_instantiation_changed (void);
extern void record_last_problematic_instantiation (void); extern void record_last_problematic_instantiation (void);
extern struct tinst_level *current_instantiation(void); extern struct tinst_level *current_instantiation(void);
extern bool instantiating_current_function_p (void);
extern tree maybe_get_template_decl_from_type_decl (tree); extern tree maybe_get_template_decl_from_type_decl (tree);
extern int processing_template_parmlist; extern int processing_template_parmlist;
extern bool dependent_type_p (tree); extern bool dependent_type_p (tree);

View File

@ -973,9 +973,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
/* If this is a locally defined typedef in a function that /* If this is a locally defined typedef in a function that
is not a template instantation, record it to implement is not a template instantation, record it to implement
-Wunused-local-typedefs. */ -Wunused-local-typedefs. */
if (current_instantiation () == NULL if (!instantiating_current_function_p ())
|| (current_instantiation ()->decl != current_function_decl)) record_locally_defined_typedef (x);
record_locally_defined_typedef (x);
} }
/* Multiple external decls of the same identifier ought to match. /* Multiple external decls of the same identifier ought to match.
@ -1277,7 +1276,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
old and new decls are type decls. */ old and new decls are type decls. */
|| (TREE_CODE (oldglobal) == TYPE_DECL || (TREE_CODE (oldglobal) == TYPE_DECL
&& (!DECL_ARTIFICIAL (oldglobal) && (!DECL_ARTIFICIAL (oldglobal)
|| TREE_CODE (x) == TYPE_DECL)))) || TREE_CODE (x) == TYPE_DECL)))
&& !instantiating_current_function_p ())
/* XXX shadow warnings in outer-more namespaces */ /* XXX shadow warnings in outer-more namespaces */
{ {
if (warning_at (input_location, OPT_Wshadow, if (warning_at (input_location, OPT_Wshadow,

View File

@ -20773,6 +20773,16 @@ current_instantiation (void)
return current_tinst_level; return current_tinst_level;
} }
/* Return TRUE if current_function_decl is being instantiated, false
otherwise. */
bool
instantiating_current_function_p (void)
{
return (current_instantiation ()
&& current_instantiation ()->decl == current_function_decl);
}
/* [temp.param] Check that template non-type parm TYPE is of an allowable /* [temp.param] Check that template non-type parm TYPE is of an allowable
type. Return zero for ok, nonzero for disallowed. Issue error and type. Return zero for ok, nonzero for disallowed. Issue error and
warning messages under control of COMPLAIN. */ warning messages under control of COMPLAIN. */

View File

@ -1,3 +1,11 @@
2015-04-01 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/56100
* g++.dg/warn/Wshadow-8.C: New.
* g++.dg/warn/Wshadow-9.C: Likewise.
* g++.dg/warn/Wshadow-10.C: Likewise.
* g++.dg/warn/Wshadow-11.C: Likewise.
2015-04-01 Bernd Edlinger <bernd.edlinger@hotmail.de> 2015-04-01 Bernd Edlinger <bernd.edlinger@hotmail.de>
* gcc.dg/pr23623.c: Added aligned attribute. * gcc.dg/pr23623.c: Added aligned attribute.

View File

@ -0,0 +1,15 @@
// PR c++/56100
// { dg-options "-Wshadow" }
struct bar
{
template <typename T>
void baz () { int foo; }
};
int foo;
int main ()
{
bar ().baz <int> ();
}

View File

@ -0,0 +1,15 @@
// PR c++/56100
// { dg-options "-Wshadow" }
int foo; // { dg-message "shadowed declaration" }
struct bar
{
template <typename T>
void baz () { int foo; } // { dg-warning "shadows a global" }
};
int main ()
{
bar ().baz <int> ();
}

View File

@ -0,0 +1,15 @@
// PR c++/56100
// { dg-options "-Wshadow" }
template <typename T>
struct bar
{
void baz () { int foo; }
};
int foo;
int main ()
{
bar <int> ().baz ();
}

View File

@ -0,0 +1,15 @@
// PR c++/56100
// { dg-options "-Wshadow" }
int foo; // { dg-message "shadowed declaration" }
template <typename T>
struct bar
{
void baz () { int foo; } // { dg-warning "shadows a global" }
};
int main ()
{
bar <int> ().baz ();
}