]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ill-formed constexpr function [PR113360]
authorJason Merrill <jason@redhat.com>
Tue, 31 Aug 2021 21:01:22 +0000 (17:01 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 17 Apr 2025 02:25:45 +0000 (22:25 -0400)
commitac31e41c584c59f8f2e381d545235a32b7c9e406
tree64aeae34a8f3b6af9638f555840fab64d24017db
parent5e3646a3cb7a03a368367b7c252b4985c7931f4a
c++: ill-formed constexpr function [PR113360]

If we already gave an error while parsing a function, we don't also need to
try to explain what's wrong with it when we later try to use it in a
constant-expression.  In the new testcase explain_invalid_constexpr_fn
couldn't find anything still in the function to complain about, so it said
because: followed by nothing.

We still try to constant-evaluate it to reduce error cascades, but we
shouldn't complain if it doesn't work very well.

This flag is similar to CLASSTYPE_ERRONEOUS that I added a while back.

PR c++/113360

gcc/cp/ChangeLog:

* cp-tree.h (struct language_function): Add erroneous bit.
* constexpr.cc (explain_invalid_constexpr_fn): Return if set.
(cxx_eval_call_expression): Quiet if set.
* parser.cc (cp_parser_function_definition_after_declarator)
* pt.cc (instantiate_body): Set it.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/constexpr-nonlit18.C: Remove redundant message.
* g++.dg/cpp1y/constexpr-diag2.C: New test.
* g++.dg/cpp1y/pr63996.C: Adjust expected errors.
* g++.dg/template/explicit-args6.C: Likewise.
* g++.dg/cpp0x/constexpr-ice21.C: Likewise.
gcc/cp/constexpr.cc
gcc/cp/cp-tree.h
gcc/cp/parser.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-ice21.C
gcc/testsuite/g++.dg/cpp1y/constexpr-diag2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/pr63996.C
gcc/testsuite/g++.dg/cpp23/constexpr-nonlit18.C
gcc/testsuite/g++.dg/template/explicit-args6.C