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:
parent
ab11c13ff3
commit
a38f55dbfd
|
@ -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.
|
||||
|
|
21
gcc/cp/pt.c
21
gcc/cp/pt.c
|
@ -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 "
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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" }
|
Loading…
Reference in New Issue