public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "david at doublewise dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/99018] New: Comparing address of array element not considered a constant expression in certain contexts
Date: Tue, 09 Feb 2021 07:05:46 +0000	[thread overview]
Message-ID: <bug-99018-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2021-02-09  7:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09  7:05 david at doublewise dot net [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99018-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).