===================================================================
@@ -1704,19 +1704,23 @@ duplicate_decls (tree newdecl, tree olddecl, bool
if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
;
- else if (TREE_CODE (olddecl) == FUNCTION_DECL)
+ else if (DECL_DECLARES_FUNCTION_P (olddecl))
{
tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
int i = 1;
- if (DECL_FUNCTION_MEMBER_P (newdecl)
- && CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (newdecl)))
+ if (DECL_FUNCTION_TEMPLATE_P (olddecl)
+ || (DECL_FUNCTION_MEMBER_P (olddecl)
+ && (/* grokfndecl passes member function templates too
+ as FUNCTION_DECLs. */
+ DECL_TEMPLATE_INFO (olddecl)
+ /* C++11 8.3.6/6.
+ Default arguments for a member function of a class
+ template shall be specified on the initial declaration
+ of the member function within the class template. */
+ || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl)))))
{
- /* C++11 8.3.6/6.
- Default arguments for a member function of a class template
- 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))
{
===================================================================
@@ -25,7 +25,7 @@ template<typename> void g3(int, int);
template<typename> void g3(int = 0, int); // { dg-error "default" }
template<typename> void g4(int, int);
-template<typename> void g4(int = 0, int) {} // { dg-error "default" "" { xfail *-*-* } }
+template<typename> void g4(int = 0, int) {} // { dg-error "default" }
template<typename> void g5();
template<typename> void g5(int = 0, int); // { dg-error "default" }
===================================================================
@@ -0,0 +1,18 @@
+// PR c++/15339
+
+template<typename> void fun(int);
+template<typename> void fun(int = 0); // { dg-error "default arguments" }
+
+class A
+{
+ template<typename> void fun(int);
+};
+
+template<typename> void A::fun(int = 0) { } // { dg-error "default arguments" }
+
+class B
+{
+ void fun(int);
+};
+
+void B::fun(int = 0) { }