From: Patrick Palka Date: Sat, 24 Apr 2021 04:01:42 +0000 (-0400) Subject: c++: Hard error with tentative parse and CTAD [PR87709] X-Git-Tag: basepoints/gcc-13~8214 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f1a2cb9c2dc09eed53da5d5787d14bec700b10b;p=thirdparty%2Fgcc.git c++: Hard error with tentative parse and CTAD [PR87709] When parsing e.g. the operand of sizeof, where both types and expressions are accepted, if during the tentative type parse we encounter an unexpected template placeholder, we must simulate an error rather than issue a real error because the expression parse can still succeed. gcc/cp/ChangeLog: PR c++/87709 * parser.c (cp_parser_type_id_1): If we see a template placeholder, first try simulating an error before issuing a real error. gcc/testsuite/ChangeLog: PR c++/87709 * g++.dg/cpp1z/class-deduction86.C: New test. --- diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index fba516efa23d..e1b1617da682 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -23270,10 +23270,13 @@ cp_parser_type_id_1 (cp_parser *parser, cp_parser_flags flags, location_t loc = type_specifier_seq.locations[ds_type_spec]; if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node)) { - error_at (loc, "missing template arguments after %qT", - auto_node); - inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", - tmpl); + if (!cp_parser_simulate_error (parser)) + { + error_at (loc, "missing template arguments after %qT", + auto_node); + inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", + tmpl); + } } else if (parser->in_template_argument_list_p) error_at (loc, "%qT not permitted in template argument", diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction86.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction86.C new file mode 100644 index 000000000000..a198ed24ec62 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction86.C @@ -0,0 +1,16 @@ +// PR c++/87709 +// { dg-do compile { target c++17 } } + +template +struct lit { + lit(T) { } +}; + +template +int operator+(lit, lit) { + return 0; +} + +auto r2 = (lit(0)) + lit(0); + +static_assert(sizeof(lit(0)));