On 4/14/21 9:21 PM, Marek Polacek wrote:
Here we ICE when compiling this code in C++20, because we're trying to
slam a 'typename' after the ->.  The cp_parser_template_id call just
before the spot I'm changing parsed A::template A<int> as a BASELINK
that contains a constructor, but make_typename_type crashes on that.

My fix is the same as c++/88325, add an is_overloaded_fn check.

Instead of handling this in various callers, maybe make_typename_type should handle the error, like it already does for e.g.

  struct A {  template <class T> static T t; };
  A(unsigned) -> A:: template t<int>;

Incidentally, in the testcase for 88325:

A<T>::A<U> () // { dg-error "partial specialization" }

this error is misleading; this isn't a partial specialization, it's redundant template arguments while trying to define the primary template. I wouldn't worry about fixing the compiler now, but let's not test for the wrong error.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

gcc/cp/ChangeLog:

        PR c++/99803
        * parser.c (cp_parser_simple_type_specifier): Don't call
        cp_parser_make_typename_type for is_overloaded_fn.

gcc/testsuite/ChangeLog:

        PR c++/99803
        * g++.dg/cpp2a/typename19.C: New test.
---
  gcc/cp/parser.c                         | 2 +-
  gcc/testsuite/g++.dg/cpp2a/typename19.C | 5 +++++
  2 files changed, 6 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/typename19.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3a107206318..3c506d891c9 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -18903,7 +18903,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
          if (TREE_CODE (type) != TYPE_DECL)
            {
              /* ...unless we pretend we have seen 'typename'.  */
-             if (typename_p)
+             if (typename_p && !is_overloaded_fn (type))
                type = cp_parser_make_typename_type (parser, type,
                                                     token->location);
              else
diff --git a/gcc/testsuite/g++.dg/cpp2a/typename19.C 
b/gcc/testsuite/g++.dg/cpp2a/typename19.C
new file mode 100644
index 00000000000..bd7e5110e00
--- /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<typename T> A(T); };
+auto A(unsigned) -> A::template A<int>; // { dg-error "not name a type" }

base-commit: a87d3f964df31d4fbceb822c6d293e85c117d992


Reply via email to