Message ID | 53DA7E85.1000806@oracle.com |
---|---|
State | New |
Headers | show |
On 07/31/2014 01:36 PM, Paolo Carlini wrote: > The problem is that when grokfndecl calls duplicate_decls in such member cases it looks through TEMPLATE_DECLs > and then telling apart the two cases above is tough, both are FUNCTION_DECLs > > Ideas about the best way to handle that? Could you just condition it on DECL_TEMPLATE_INFO? > tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); > int i = 1; > > - if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) > + if (DECL_NONSTATIC_MEMBER_FUNCTION_P (newdecl)) > t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); Let's use FUNCTION_FIRST_USER_PARMTYPE instead. > - if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE > + if (DECL_FUNCTION_MEMBER_P (newdecl) This change is OK. and in the predicate patch: > - || TREE_CODE (TREE_TYPE (target_type)) != METHOD_TYPE); > + || !DECL_NONSTATIC_MEMBER_FUNCTION_P (target_type)); This is wrong because target_type is not a FUNCTION_DECL. We should probably either add FUNCTION_DECL_CHECK to DECL_NONSTATIC_MEMBER_FUNCTION_P or make it false if the argument isn't a FUNCTION_DECL. There are a bunch of instances of this in the patch. > if (TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE > - || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE > + || DECL_NONSTATIC_MEMBER_FUNCTION_P (expr) Changing this instance and similar ones doesn't make much sense since the condition is looking for any kind of function, not just a non-static member function. Jason
Index: cp/decl.c =================================================================== --- cp/decl.c (revision 213379) +++ cp/decl.c (working copy) @@ -1710,10 +1710,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); int i = 1; - if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) + if (DECL_NONSTATIC_MEMBER_FUNCTION_P (newdecl)) t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); - if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE + if (DECL_FUNCTION_MEMBER_P (newdecl) && CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (newdecl))) { /* C++11 8.3.6/6. Index: testsuite/g++.dg/tc1/dr217-2.C =================================================================== --- testsuite/g++.dg/tc1/dr217-2.C (revision 0) +++ testsuite/g++.dg/tc1/dr217-2.C (working copy) @@ -0,0 +1,13 @@ +// { dg-do compile } +// DR217: Default arguments for non-template member functions of class +// templates + +template <class T> +struct S +{ + static void foo (int); +}; + +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" } +{ }