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

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).