diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2013-11-25 22:24:58 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2013-11-25 22:24:58 +0000 |
commit | 97d12d29aaf0502b243d7a39dc22bd7a8074b039 (patch) | |
tree | 953843fe30524203dce49ad0d86d59500fe7b653 /gcc/cp | |
parent | 4fd602a1e050ca035265ae53f2dfe721505811a5 (diff) | |
download | gcc-97d12d29aaf0502b243d7a39dc22bd7a8074b039.zip gcc-97d12d29aaf0502b243d7a39dc22bd7a8074b039.tar.gz gcc-97d12d29aaf0502b243d7a39dc22bd7a8074b039.tar.bz2 |
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
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/decl.c | 52 |
2 files changed, 43 insertions, 15 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e567aa0..64f9a23 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 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 * semantics.c (check_constexpr_ctor_body): Check for BIND_EXPR_VARS. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 75e29f4..bf4d8e3 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -1704,25 +1704,47 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); - for (; t1 && t1 != void_list_node; - t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) - if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) - { - if (1 == simple_cst_equal (TREE_PURPOSE (t1), - TREE_PURPOSE (t2))) + if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE + && CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (newdecl))) + { + /* 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)) { - permerror (input_location, "default argument given for parameter %d of %q#D", - i, newdecl); - permerror (input_location, "after previous specification in %q+#D", olddecl); + permerror (input_location, + "redeclaration of %q#D may not have default " + "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", - i, newdecl); - error ("after previous specification in %q+#D", - olddecl); + if (1 == simple_cst_equal (TREE_PURPOSE (t1), + TREE_PURPOSE (t2))) + { + 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); + } } - } + } } } |