Commit 97d12d29 by Paolo Carlini Committed by Paolo Carlini

re PR c++/54485 (g++ should diagnose default arguments in out-of-line…

re PR c++/54485 (g++ should diagnose default arguments in out-of-line definitions for template class member functions)

/cp
2013-11-25  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54485
	* decl.c (duplicate_decls): Enforce 8.3.6/6 about default arguments
	for member functions of class templates.

/testsuite
2013-11-25  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54485
	* g++.dg/other/default8.C: New.
	* g++.dg/tc1/dr217.C: Remove xfail.
	* g++.dg/other/default5.C: Adjust.
	* g++.old-deja/g++.mike/p1989.C: Likewise.

From-SVN: r205367
parent 4fd602a1
2013-11-25 Paolo Carlini <paolo.carlini@oracle.com> 2013-11-25 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/54485
* decl.c (duplicate_decls): Enforce 8.3.6/6 about default arguments
for member functions of class templates.
2013-11-25 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58607 PR c++/58607
* semantics.c (check_constexpr_ctor_body): Check for BIND_EXPR_VARS. * semantics.c (check_constexpr_ctor_body): Check for BIND_EXPR_VARS.
......
...@@ -1704,25 +1704,47 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) ...@@ -1704,25 +1704,47 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
for (; t1 && t1 != void_list_node; if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE
t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) && CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (newdecl)))
if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) {
{ /* C++11 8.3.6/6.
if (1 == simple_cst_equal (TREE_PURPOSE (t1), Default arguments for a member function of a class template
TREE_PURPOSE (t2))) shall be specified on the initial declaration of the member
function within the class template. */
for (; t2 && t2 != void_list_node; t2 = TREE_CHAIN (t2))
if (TREE_PURPOSE (t2))
{ {
permerror (input_location, "default argument given for parameter %d of %q#D", permerror (input_location,
i, newdecl); "redeclaration of %q#D may not have default "
permerror (input_location, "after previous specification in %q+#D", olddecl); "arguments", newdecl);
break;
} }
else }
else
{
for (; t1 && t1 != void_list_node;
t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
{ {
error ("default argument given for parameter %d of %q#D", if (1 == simple_cst_equal (TREE_PURPOSE (t1),
i, newdecl); TREE_PURPOSE (t2)))
error ("after previous specification in %q+#D", {
olddecl); permerror (input_location,
"default argument given for parameter %d "
"of %q#D", i, newdecl);
permerror (input_location,
"after previous specification in %q+#D",
olddecl);
}
else
{
error ("default argument given for parameter %d "
"of %q#D", i, newdecl);
error ("after previous specification in %q+#D",
olddecl);
}
} }
} }
} }
} }
......
2013-11-25 Paolo Carlini <paolo.carlini@oracle.com> 2013-11-25 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/54485
* g++.dg/other/default8.C: New.
* g++.dg/tc1/dr217.C: Remove xfail.
* g++.dg/other/default5.C: Adjust.
* g++.old-deja/g++.mike/p1989.C: Likewise.
2013-11-25 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58607 PR c++/58607
* g++.dg/cpp0x/constexpr-ice9.C: New. * g++.dg/cpp0x/constexpr-ice9.C: New.
......
...@@ -43,5 +43,5 @@ template<int> struct B ...@@ -43,5 +43,5 @@ template<int> struct B
void F2(int, int, int = 0); void F2(int, int, int = 0);
}; };
template<int N> void B<N>::F1(int, int = 0, int) {} template<int N> void B<N>::F1(int, int = 0, int) {} // { dg-error "default arguments" }
template<int N> void B<N>::F2(int = 0, int, int) {} // { dg-error "default" } template<int N> void B<N>::F2(int = 0, int, int) {} // { dg-error "default arguments|parameter 2" }
// PR c++54485
template<typename T>
class K1
{
int fn(int, int);
int gn(int, int);
};
template<typename T>
int K1<T>::fn (int a, int b = 3) // { dg-error "default arguments" }
{
return a - b;
}
template<typename T>
int K1<T>::gn (int a = 1, int b = 3) // { dg-error "default arguments" }
{
return a - b;
}
template<typename T>
class K2
{
template<typename U>
int fn(int, int);
template<typename U>
int gn(int, int);
};
template<typename T>
template<typename U>
int K2<T>::fn (int a, int b = 3) // { dg-error "default arguments" }
{
return a - b;
}
template<typename T>
template<typename U>
int K2<T>::gn (int a = 1, int b = 3) // { dg-error "default arguments" }
{
return a - b;
}
...@@ -10,5 +10,5 @@ struct S ...@@ -10,5 +10,5 @@ struct S
}; };
template <class T> template <class T>
void S<T>::foo (int = 0) // { dg-error "" "default arguments for parameters of member functions of class templates can be specified in the initial declaration only" { xfail *-*-* } } void S<T>::foo (int = 0) // { dg-error "" "default arguments for parameters of member functions of class templates can be specified in the initial declaration only" }
{ } { }
...@@ -108,7 +108,7 @@ List_DL<T>::prepend(const T& item) ...@@ -108,7 +108,7 @@ List_DL<T>::prepend(const T& item)
template<class T> template<class T>
void void
List_DL<T>::insert(const T& item, Pix x, bool before = TRUE) List_DL<T>::insert(const T& item, Pix x, bool before = TRUE) // { dg-error "default arguments" }
{ {
link<T> *l = (link<T> *) x; link<T> *l = (link<T> *) x;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment