}
}
+ if (deduction_guide_p (olddecl)
+ && deduction_guide_p (newdecl))
+ return G_("deduction guide %q+D redeclared");
+
/* [class.compare.default]: A definition of a comparison operator as
defaulted that appears in a class shall be the first declaration of
that function. */
"%<gnu_inline%> attribute");
else
return G_("%q+D redeclared inline without "
- "%<gnu_inline%> attribute");
+ "%<gnu_inline%> attribute");
}
}
- /* Core issue #226 (C++0x):
-
+ if (deduction_guide_p (olddecl)
+ && deduction_guide_p (newdecl))
+ return G_("deduction guide %q+D redeclared");
+
+ /* Core issue #226 (C++11):
+
If a friend function template declaration specifies a
default template-argument, that declaration shall be a
definition and shall be the only declaration of the
function template in the translation unit. */
- if ((cxx_dialect != cxx98)
+ if ((cxx_dialect != cxx98)
&& TREE_CODE (ot) == FUNCTION_DECL && DECL_FRIEND_P (ot)
- && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
+ && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
/*is_primary=*/true,
/*is_partial=*/false,
/*is_friend_decl=*/2))
return G_("redeclaration of friend %q#D "
- "may not have default template arguments");
+ "may not have default template arguments");
return NULL;
}
--- /dev/null
+// PR c++/97099
+// { dg-do compile { target c++17 } }
+// [temp.deduct.guide]p3: Two deduction guide declarations in the same
+// translation unit for the same class template shall not have equivalent
+// parameter-declaration-clauses.
+
+template<typename> struct S { };
+template<typename> struct X { };
+
+S() -> S<int>; // { dg-message "previously declared here|old declaration" }
+S() -> S<int>; // { dg-error "redeclared" }
+X() -> X<int>;
+S() -> S<float>; // { dg-error "ambiguating new declaration of" }
+
+S(bool) -> S<int>; // { dg-message "previously declared here" }
+explicit S(bool) -> S<int>; // { dg-error "redeclared" }
+
+explicit S(char) -> S<int>; // { dg-message "previously declared here" }
+S(char) -> S<int>; // { dg-error "redeclared" }
+
+template<typename T> S(T, T) -> S<int>; // { dg-message "previously declared here" }
+template<typename T> X(T, T) -> X<int>;
+template<typename T> S(T, T) -> S<int>; // { dg-error "redeclared" }
+
+// OK: Use SFINAE.
+template<typename T> S(T) -> S<typename T::foo>;
+template<typename T> S(T) -> S<typename T::bar>;
+
+// OK: Non-template wins.
+S(int) -> S<int>;
+template<typename T = int> S(int) -> S<char>;