diff options
author | Marek Polacek <polacek@redhat.com> | 2023-09-01 17:26:01 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2023-09-05 14:21:03 -0400 |
commit | b78cedc6b5bc062717a3e0efb10da8e19af1c422 (patch) | |
tree | 8703c35b1c2243f579386dc71ef551aae5ca31fc /gcc/c/c-decl.cc | |
parent | decbf9ec81f33052be12296b89cd86ea65ae10da (diff) | |
download | gcc-b78cedc6b5bc062717a3e0efb10da8e19af1c422.zip gcc-b78cedc6b5bc062717a3e0efb10da8e19af1c422.tar.gz gcc-b78cedc6b5bc062717a3e0efb10da8e19af1c422.tar.bz2 |
c++: improve verify_constant diagnostic [PR91483]
When verify_constant complains, it's pretty terse. Consider
void test ()
{
constexpr int i = 42;
constexpr const int *p = &i;
}
where it says "'& i' is not a constant expression". OK, but why?
With this patch, we say:
b.C:5:28: error: '& i' is not a constant expression
5 | constexpr const int *p = &i;
| ^~
b.C:5:28: note: pointer to 'i' is not a constant expression
b.C:4:17: note: address of non-static constexpr variable 'i' may differ on each invocation of the enclosing function; add 'static' to give it a constant address
4 | constexpr int i = 42;
| ^
| static
which brings g++ on par with clang++.
PR c++/91483
gcc/cp/ChangeLog:
* constexpr.cc (verify_constant_explain_r): New.
(verify_constant): Call it.
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/constexpr3.C: New test.
Diffstat (limited to 'gcc/c/c-decl.cc')
0 files changed, 0 insertions, 0 deletions