public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/91483] Poor diagnostic on trying to take constexpr reference to non-static object
[not found] <bug-91483-4@http.gcc.gnu.org/bugzilla/>
@ 2020-09-08 15:41 ` mpolacek at gcc dot gnu.org
2023-08-25 20:26 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-09-08 15:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91483
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Related test:
void
foo ()
{
constexpr int a = 0;
constexpr const int *p = &a;
}
We just say
error: ‘& a’ is not a constant expression
but that's inadequate. clang++ now says
note: address of non-static constexpr variable 'a' may differ on each
invocation of the enclosing function; add 'static' to give it a constant
address
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/91483] Poor diagnostic on trying to take constexpr reference to non-static object
[not found] <bug-91483-4@http.gcc.gnu.org/bugzilla/>
2020-09-08 15:41 ` [Bug c++/91483] Poor diagnostic on trying to take constexpr reference to non-static object mpolacek at gcc dot gnu.org
@ 2023-08-25 20:26 ` mpolacek at gcc dot gnu.org
2023-09-05 18:30 ` cvs-commit at gcc dot gnu.org
2023-09-05 18:32 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-08-25 20:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91483
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The error comes from verify_constant, which doesn't explain anything.
verify_constant uses reduced_constant_expression_p which just says yes/no but
doesn't explain anything. reduced_constant_expression_p uses the middle-end
initializer_constant_valid_p but that's not going to say anything, either.
Either we need a version of reduced_constant_expression_p that actually says
what's wrong, or add a function that, when given an expression that isn't
reduced_constant_expression_p, will look for known problematical cases, like
the one above.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/91483] Poor diagnostic on trying to take constexpr reference to non-static object
[not found] <bug-91483-4@http.gcc.gnu.org/bugzilla/>
2020-09-08 15:41 ` [Bug c++/91483] Poor diagnostic on trying to take constexpr reference to non-static object mpolacek at gcc dot gnu.org
2023-08-25 20:26 ` mpolacek at gcc dot gnu.org
@ 2023-09-05 18:30 ` cvs-commit at gcc dot gnu.org
2023-09-05 18:32 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-05 18:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91483
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:b78cedc6b5bc062717a3e0efb10da8e19af1c422
commit r14-3718-gb78cedc6b5bc062717a3e0efb10da8e19af1c422
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Sep 1 17:26:01 2023 -0400
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/91483] Poor diagnostic on trying to take constexpr reference to non-static object
[not found] <bug-91483-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2023-09-05 18:30 ` cvs-commit at gcc dot gnu.org
@ 2023-09-05 18:32 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-09-05 18:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91483
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Should be fixed now.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-05 18:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-91483-4@http.gcc.gnu.org/bugzilla/>
2020-09-08 15:41 ` [Bug c++/91483] Poor diagnostic on trying to take constexpr reference to non-static object mpolacek at gcc dot gnu.org
2023-08-25 20:26 ` mpolacek at gcc dot gnu.org
2023-09-05 18:30 ` cvs-commit at gcc dot gnu.org
2023-09-05 18:32 ` mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).