Hi,
On 03/10/2015 07:10 PM, Jason Merrill wrote:
Ah. So here we can ignore any template instantiation or
specialization, with a comment that check_explicit_specialization will
handle them. But I suspect that checking the decl itself will be
better; I would expect checking the context to lead you to accept
template<> class C<int> {
template <typename U>
C(const C<U>&, bool);
};
template <typename U> C<int>::C(const C<U>&, bool = false);
Since here C<int> is a specialization of C, but the constructor is not
itself a partial instantiation.
Indeed you are right. Therefore I'm finishing testing the below.
Thanks!
Paolo.
////////////////////////
/cp
2015-03-10 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/65370
* decl.c (duplicate_decls): Call check_redeclaration_no_default_args
only if the location of newdecl doesn't match the location of olddecl.
/testsuite
2015-03-10 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/65370
* g++.dg/other/default11.C: New.
* g++.dg/other/default12.C: Likewise.
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 221317)
+++ cp/decl.c (working copy)
@@ -1922,7 +1922,9 @@ duplicate_decls (tree newdecl, tree olddecl, bool
{
/* Per C++11 8.3.6/4, default arguments cannot be added in later
declarations of a function template. */
- check_redeclaration_no_default_args (newdecl);
+ if (DECL_SOURCE_LOCATION (newdecl)
+ != DECL_SOURCE_LOCATION (olddecl))
+ check_redeclaration_no_default_args (newdecl);
check_default_args (newdecl);
Index: testsuite/g++.dg/other/default11.C
===================================================================
--- testsuite/g++.dg/other/default11.C (revision 0)
+++ testsuite/g++.dg/other/default11.C (working copy)
@@ -0,0 +1,11 @@
+// PR c++/65370
+
+template <typename> class C
+{
+ template <typename U>
+ C(const C<U>&, bool = false);
+};
+
+template <>
+template <typename U>
+C<int>::C(const C<U>&, bool);
Index: testsuite/g++.dg/other/default12.C
===================================================================
--- testsuite/g++.dg/other/default12.C (revision 0)
+++ testsuite/g++.dg/other/default12.C (working copy)
@@ -0,0 +1,16 @@
+// PR c++/65370
+
+template <typename> class C
+{
+ template <typename U>
+ C(const C<U>&, bool = false);
+};
+
+template<>
+class C<int>
+{
+ template <typename U>
+ C(const C<U>&, bool);
+};
+
+template <typename U> C<int>::C(const C<U>&, bool = false) { } // { dg-error
"default arguments" }