diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d40b7a7da5f..942eb318f2c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4055,6 +4055,12 @@ make_typename_type (tree context, tree name, enum tag_types tag_type, error ("%qD used without template arguments", name); return error_mark_node; } + else if (is_overloaded_fn (name)) + { + if (complain & tf_error) + error ("%qD is a function, not a type", name); + return error_mark_node; + } gcc_assert (identifier_p (name)); gcc_assert (TYPE_P (context)); @@ -4066,7 +4072,7 @@ make_typename_type (tree context, tree name, enum tag_types tag_type, error ("%q#T is not a class", context); return error_mark_node; } - + /* When the CONTEXT is a dependent type, NAME could refer to a dependent base class of CONTEXT. But look inside it anyway if CONTEXT is a currently open scope, in case it refers to a diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index dfc9b8251a7..99eccf0c5e4 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -24730,9 +24730,7 @@ cp_parser_class_name (cp_parser *parser, decl = cp_parser_maybe_treat_template_as_class (decl, class_head_p); /* If this is a typename, create a TYPENAME_TYPE. */ - if (typename_p - && decl != error_mark_node - && !is_overloaded_fn (decl)) + if (typename_p && decl != error_mark_node) { decl = make_typename_type (scope, decl, typename_type, /*complain=*/tf_error); diff --git a/gcc/testsuite/g++.dg/cpp2a/typename14.C b/gcc/testsuite/g++.dg/cpp2a/typename14.C index 8d82b6b8d34..ba7dad8245f 100644 --- a/gcc/testsuite/g++.dg/cpp2a/typename14.C +++ b/gcc/testsuite/g++.dg/cpp2a/typename14.C @@ -8,7 +8,7 @@ template struct A template template -A::A () // { dg-error "partial specialization" } +A::A () // { dg-error "" } { } @@ -19,7 +19,7 @@ template struct B template template -B::foo(int) // { dg-error "partial specialization|declaration" } +B::foo(int) // { dg-error "" } { return 1; } diff --git a/gcc/testsuite/g++.dg/cpp2a/typename19.C b/gcc/testsuite/g++.dg/cpp2a/typename19.C new file mode 100644 index 00000000000..320a14d6a0c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/typename19.C @@ -0,0 +1,5 @@ +// PR c++/99803 +// { dg-do compile { target c++20 } } + +struct A { template A(T); }; +auto A(unsigned) -> A::template A; // { dg-error "not a type" }