public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99018] New: Comparing address of array element not considered a constant expression in certain contexts
@ 2021-02-09 7:05 david at doublewise dot net
2021-02-09 20:53 ` [Bug c++/99018] " david at doublewise dot net
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: david at doublewise dot net @ 2021-02-09 7:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99018
Bug ID: 99018
Summary: Comparing address of array element not considered a
constant expression in certain contexts
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: david at doublewise dot net
Target Milestone: ---
The following valid translation unit
```
struct s {
constexpr s() = default;
constexpr s(s const & other) {
if (this == &other) {
}
}
};
constexpr auto f() {
s init[2];
for (auto & element : init) {
s foo = element;
}
return true;
}
static_assert(f());
```
is rejected by gcc with
```
<source>:18:16: error: non-constant condition for static assertion
18 | static_assert(f());
| ~^~
<source>:18:16: in 'constexpr' expansion of 'f()'
<source>:13:11: in 'constexpr' expansion of 's((*(const s*)(& element)))'
<source>:5:26: error: '(((const s*)(& foo)) == (((const s*)(& init)) + 1))' is
not a constant expression
5 | if (this == &other) {
| ~~~~~^~~~~~~~~
Compiler returned: 1
```
See it live: https://godbolt.org/z/xG5dv5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/99018] Comparing address of array element not considered a constant expression in certain contexts
2021-02-09 7:05 [Bug c++/99018] New: Comparing address of array element not considered a constant expression in certain contexts david at doublewise dot net
@ 2021-02-09 20:53 ` david at doublewise dot net
2021-03-03 17:34 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: david at doublewise dot net @ 2021-02-09 20:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99018
David Stone <david at doublewise dot net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |david at doublewise dot net
--- Comment #1 from David Stone <david at doublewise dot net> ---
Here's a simpler test case
```
struct s {
constexpr ~s() {
if (this) {
}
}
};
constexpr bool f(s (&&)[1]) {
return true;
}
static_assert(f(
{s()}
));
```
Message:
```
<source>:12:16: error: non-constant condition for static assertion
12 | static_assert(f(
| ~^
13 | {s()}
| ~~~~~
14 | ));
| ~
<source>:14:1: error: '(((s*)(&<anonymous>)) != 0)' is not a constant
expression
14 | ));
| ^
Compiler returned: 1
```
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/99018] Comparing address of array element not considered a constant expression in certain contexts
2021-02-09 7:05 [Bug c++/99018] New: Comparing address of array element not considered a constant expression in certain contexts david at doublewise dot net
2021-02-09 20:53 ` [Bug c++/99018] " david at doublewise dot net
@ 2021-03-03 17:34 ` mpolacek at gcc dot gnu.org
2021-03-10 22:02 ` david at doublewise dot net
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-03-03 17:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99018
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
CC| |mpolacek at gcc dot gnu.org
Last reconfirmed| |2021-03-03
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/99018] Comparing address of array element not considered a constant expression in certain contexts
2021-02-09 7:05 [Bug c++/99018] New: Comparing address of array element not considered a constant expression in certain contexts david at doublewise dot net
2021-02-09 20:53 ` [Bug c++/99018] " david at doublewise dot net
2021-03-03 17:34 ` mpolacek at gcc dot gnu.org
@ 2021-03-10 22:02 ` david at doublewise dot net
2021-08-02 19:05 ` davidfromonline at gmail dot com
2022-01-14 14:02 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: david at doublewise dot net @ 2021-03-10 22:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99018
--- Comment #2 from David Stone <david at doublewise dot net> ---
Simpler test case
```
struct s {
constexpr ~s() {
}
};
constexpr bool f(s const (&)[1]) {
return true;
}
static_assert(f({s()}));
```
Message
```
<source>:10:16: error: non-constant condition for static assertion
10 | static_assert(f({s()}));
| ~^~~~~~~
<source>:10:22: error: '(((const s*)(&<anonymous>)) != 0)' is not a constant
expression
10 | static_assert(f({s()}));
| ^
Compiler returned: 1
```
See it live: https://godbolt.org/z/YGYjfh
You can get the same error by making the function parameter
`std::initializer_list<s>` as well. Especially interesting in this reduction is
that the code complains about a comparison, but there is no comparison anywhere
in the code.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/99018] Comparing address of array element not considered a constant expression in certain contexts
2021-02-09 7:05 [Bug c++/99018] New: Comparing address of array element not considered a constant expression in certain contexts david at doublewise dot net
` (2 preceding siblings ...)
2021-03-10 22:02 ` david at doublewise dot net
@ 2021-08-02 19:05 ` davidfromonline at gmail dot com
2022-01-14 14:02 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: davidfromonline at gmail dot com @ 2021-08-02 19:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99018
--- Comment #3 from David Stone <davidfromonline at gmail dot com> ---
The error message looks suspiciously similar to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85944. Perhaps it's the same bug?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/99018] Comparing address of array element not considered a constant expression in certain contexts
2021-02-09 7:05 [Bug c++/99018] New: Comparing address of array element not considered a constant expression in certain contexts david at doublewise dot net
` (3 preceding siblings ...)
2021-08-02 19:05 ` davidfromonline at gmail dot com
@ 2022-01-14 14:02 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-14 14:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99018
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
GCC trunk accepts the first testcase ever since r12-6382.
(In reply to David Stone from comment #3)
> The error message looks suspiciously similar to
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85944. Perhaps it's the same
> bug?
Hmm yeah, it looks like the other testcases here are the same bug as PR85944.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-01-14 14:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 7:05 [Bug c++/99018] New: Comparing address of array element not considered a constant expression in certain contexts david at doublewise dot net
2021-02-09 20:53 ` [Bug c++/99018] " david at doublewise dot net
2021-03-03 17:34 ` mpolacek at gcc dot gnu.org
2021-03-10 22:02 ` david at doublewise dot net
2021-08-02 19:05 ` davidfromonline at gmail dot com
2022-01-14 14:02 ` ppalka 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).