public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103732] New: Incorrect constexpr evaluation of runtime expression
@ 2021-12-15 11:43 gonzalo.gadeschi at gmail dot com
2021-12-15 11:47 ` [Bug c++/103732] " pinskia at gcc dot gnu.org
2021-12-15 19:45 ` gonzalo.gadeschi at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: gonzalo.gadeschi at gmail dot com @ 2021-12-15 11:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103732
Bug ID: 103732
Summary: Incorrect constexpr evaluation of runtime expression
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gonzalo.gadeschi at gmail dot com
Target Milestone: ---
GCC 11.2 accepts the following example:
struct S { static constexpr int C = 5; };
void f() {
S s0{}, s1{};
S* a[] = {&s0, &s1};
for (int i = 0; i < 2; ++i) {
constexpr int x = S::C;
constexpr int y = s0.C;
constexpr int z = a[i]->C;
}
}
According to http://eel.is/c++draft/class.static#general-1, the object
expression of s0.C and a[i]->C are evaluated, but for example, a[i] is not a
constant expression.
I think GCC is incorrectly accepting this code.
Clang produces the following error:
<source>:10:23: error: constexpr variable 'z' must be initialized by a constant
expression
constexpr int z = a[i]->C;
^ ~~~~~~~
<source>:10:29: note: read of non-const variable 'i' is not allowed in a
constant expression
constexpr int z = a[i]->C;
^
<source>:7:14: note: declared here
for (int i = 0; i < 2; ++i) {
^
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/103732] Incorrect constexpr evaluation of runtime expression
2021-12-15 11:43 [Bug c++/103732] New: Incorrect constexpr evaluation of runtime expression gonzalo.gadeschi at gmail dot com
@ 2021-12-15 11:47 ` pinskia at gcc dot gnu.org
2021-12-15 19:45 ` gonzalo.gadeschi at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-15 11:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103732
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
ICC and MSVC both accept it like GCC ....
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/103732] Incorrect constexpr evaluation of runtime expression
2021-12-15 11:43 [Bug c++/103732] New: Incorrect constexpr evaluation of runtime expression gonzalo.gadeschi at gmail dot com
2021-12-15 11:47 ` [Bug c++/103732] " pinskia at gcc dot gnu.org
@ 2021-12-15 19:45 ` gonzalo.gadeschi at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: gonzalo.gadeschi at gmail dot com @ 2021-12-15 19:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103732
--- Comment #2 from gnzlbg <gonzalo.gadeschi at gmail dot com> ---
> ICC and MSVC both accept it like GCC ....
That's correct, please feel free to report the bug to them as well.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-12-15 19:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15 11:43 [Bug c++/103732] New: Incorrect constexpr evaluation of runtime expression gonzalo.gadeschi at gmail dot com
2021-12-15 11:47 ` [Bug c++/103732] " pinskia at gcc dot gnu.org
2021-12-15 19:45 ` gonzalo.gadeschi at gmail dot com
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).