From 875225301e356759982573d5578ed7ca54f81f86 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 3 Nov 2020 21:42:51 +0100 Subject: [PATCH] c++: Don't try to parse a function declaration as deduction guide [PR97663] While these function declarations have NULL decl_specifiers->type, they have still type specifiers specified from which the default int in the return type is added, so we shouldn't try to parse those as deduction guides. 2020-11-03 Jakub Jelinek PR c++/97663 * parser.c (cp_parser_init_declarator): Don't try to parse C++17 deduction guides if there are any type specifiers even when type is NULL. * g++.dg/cpp1z/class-deduction75.C: New test. --- gcc/cp/parser.c | 1 + gcc/testsuite/g++.dg/cpp1z/class-deduction75.C | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction75.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 274797f1879..b0d5c69f1d6 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -20790,6 +20790,7 @@ cp_parser_init_declarator (cp_parser* parser, { /* Handle C++17 deduction guides. */ if (!decl_specifiers->type + && !decl_specifiers->any_type_specifiers_p && ctor_dtor_or_conv_p <= 0 && cxx_dialect >= cxx17) { diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction75.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction75.C new file mode 100644 index 00000000000..52e6131c7b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction75.C @@ -0,0 +1,15 @@ +// PR c++/97663 + +template struct foo {}; +template struct bar {}; +template struct baz {}; +template struct qux {}; +template struct corge {}; + +namespace N { + unsigned foo (); + signed bar (); + long baz (); + long long qux (); + short corge (); +} -- 2.30.2