diff options
author | Marek Polacek <polacek@redhat.com> | 2024-01-15 09:15:59 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-01-15 18:39:32 -0500 |
commit | a3054489117085c095e480c71b6aaeea9a463c37 (patch) | |
tree | b7a78a7e8458c36813b27c16cc9db364722baa47 /gcc/cp | |
parent | 2e3a75f714c1bba876c31d0e68e903c6857d83a9 (diff) | |
download | gcc-a3054489117085c095e480c71b6aaeea9a463c37.zip gcc-a3054489117085c095e480c71b6aaeea9a463c37.tar.gz gcc-a3054489117085c095e480c71b6aaeea9a463c37.tar.bz2 |
c++: ICE with auto in template arg [PR110065]
Here we started crashing with r14-1659 because that removed the
auto checking in cp_parser_template_type_arg which seemed like
dead code. But the attached test shows that the code can still
be reached because cp_parser_type_id_1 checks auto only when
auto_is_implicit_function_template_parm_p is on.
Then I noticed that we're still crashing in C++20, and that ICE
started with r12-4772. So I changed the reemerged check to use
flag_concepts_ts rather than flag_concepts on the basis that
check_auto_in_tmpl_args also checks flag_concepts_ts.
PR c++/110065
gcc/cp/ChangeLog:
* parser.cc (cp_parser_template_type_arg): Add auto checking.
gcc/testsuite/ChangeLog:
* g++.dg/concepts/auto8.C: New test.
* g++.dg/concepts/auto8a.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/parser.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index fd614ba..c7ad3ec 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -25063,12 +25063,20 @@ cp_parser_type_id (cp_parser *parser, cp_parser_flags flags, static tree cp_parser_template_type_arg (cp_parser *parser) { - tree r; const char *saved_message = parser->type_definition_forbidden_message; parser->type_definition_forbidden_message = G_("types may not be defined in template arguments"); - r = cp_parser_type_id_1 (parser, CP_PARSER_FLAGS_NONE, true, false, NULL); + tree r = cp_parser_type_id_1 (parser, CP_PARSER_FLAGS_NONE, + /*is_template_arg=*/true, + /*is_trailing_return=*/false, nullptr); parser->type_definition_forbidden_message = saved_message; + /* cp_parser_type_id_1 checks for auto, but only for + ->auto_is_implicit_function_template_parm_p. */ + if (cxx_dialect >= cxx14 && !flag_concepts_ts && type_uses_auto (r)) + { + error ("invalid use of %<auto%> in template argument"); + r = error_mark_node; + } return r; } |