re PR c++/35075 (ICE with references in templates)

PR c++/35075
	* pt.c (convert_nontype_argument): Give helpful error about
	reference variable argument to reference template parameter.

From-SVN: r154151
This commit is contained in:
Jason Merrill 2009-11-13 09:40:32 -05:00 committed by Jason Merrill
parent ab11c13ff3
commit a38f55dbfd
4 changed files with 39 additions and 0 deletions

View File

@ -1,5 +1,9 @@
2009-11-13 Jason Merrill <jason@redhat.com>
PR c++/35075
* pt.c (convert_nontype_argument): Give helpful error about
reference variable argument to reference template parameter.
PR c++/21008, DR 515
* semantics.c (finish_non_static_data_member): Don't check
derivation in a template.

View File

@ -4927,6 +4927,27 @@ convert_nontype_argument (tree type, tree expr)
shall be one of: [...]
-- the address of an object or function with external linkage. */
if (TREE_CODE (expr) == INDIRECT_REF
&& TYPE_REF_OBJ_P (TREE_TYPE (TREE_OPERAND (expr, 0))))
{
expr = TREE_OPERAND (expr, 0);
if (DECL_P (expr))
{
error ("%q#D is not a valid template argument for type %qT "
"because a reference variable does not have a constant "
"address", expr, type);
return NULL_TREE;
}
}
if (!DECL_P (expr))
{
error ("%qE is not a valid template argument for type %qT "
"because it is not an object with external linkage",
expr, type);
return NULL_TREE;
}
if (!DECL_EXTERNAL_LINKAGE_P (expr))
{
error ("%qE is not a valid template argument for type %qT "

View File

@ -1,5 +1,8 @@
2009-11-13 Jason Merrill <jason@redhat.com>
PR c++/35075
* g++.dg/template/ref5.C: New.
PR c++/21008, DR 515
* g++.dg/template/inherit4.C: New.
* g++.dg/lookup/scoped8.C: Adjust.

View File

@ -0,0 +1,11 @@
// PR c++/35075
template<int&> struct A {};
template<typename T> struct B
{
static const T t;
A<t> a; // { dg-error "reference variable" }
};
B<int&> b; // { dg-message "instantiated" }