diff options
author | Marek Polacek <polacek@redhat.com> | 2025-02-20 14:35:25 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2025-02-27 10:53:19 -0500 |
commit | 3605e057040ead00c072c20bfbb8f26636f8295e (patch) | |
tree | 9ccc1c2dcd4ea4919786c17f83085e4f6e05e604 /libgfortran/generated/pow_m8_m2.c | |
parent | 767a7a06915651da173b6751959a47487351ed3a (diff) | |
download | gcc-3605e057040ead00c072c20bfbb8f26636f8295e.zip gcc-3605e057040ead00c072c20bfbb8f26636f8295e.tar.gz gcc-3605e057040ead00c072c20bfbb8f26636f8295e.tar.bz2 |
c++: too many errors with sneaky template [PR118516]
Since C++20 P0846, a name followed by a < can be treated as a template-name
even though name lookup did not find a template-name. That happens
in this test with "i < foo ()":
for (int id = 0; i < foo(); ++id);
and results in a raft of errors about non-constant foo(). The problem
is that the require_potential_constant_expression call in
cp_parser_template_argument emits errors even when we're parsing
tentatively. So we repeat the error when we're trying to parse
as a nested-name-specifier, type-name, etc.
Guarding the call with !cp_parser_uncommitted_to_tentative_parse_p would
mean that require_potential_constant_expression never gets called. But
we don't need the call at all as far as I can tell. Stuff like
template<int N> struct S { };
int foo () { return 4; }
void
g ()
{
S<foo()> s;
}
gets diagnosed in convert_nontype_argument. In fact, with this patch,
we only emit "call to non-constexpr function" once. (That is, in C++17
only; C++14 uses a different path.)
PR c++/118516
gcc/cp/ChangeLog:
* parser.cc (cp_parser_template_argument): Don't call
require_potential_constant_expression.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/fn-template11.C:
* g++.dg/template/fn-template1.C: New test.
* g++.dg/template/fn-template2.C: New test.
Diffstat (limited to 'libgfortran/generated/pow_m8_m2.c')
0 files changed, 0 insertions, 0 deletions