public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96557] New: Diagnostics: Can you tell me why it's not a constant expression?
@ 2020-08-10 16:25 barry.revzin at gmail dot com
  2020-08-10 16:40 ` [Bug c++/96557] " mpolacek at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: barry.revzin at gmail dot com @ 2020-08-10 16:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96557

            Bug ID: 96557
           Summary: Diagnostics: Can you tell me why it's not a constant
                    expression?
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider:

struct X {
    char storage[100] = {};
    char const* head = storage;
};

void f() {
    constexpr X x = {};
}

gcc correctly rejects this with:

error: 'X{"", ((const char*)(& x.X::storage))}' is not a constant expression
    7 |     constexpr X x = {};
      |                      ^

It'd be great if the error here actually indicated _why_ it's not a constant
expression (or how to fix it). clang does a little bit better:

<source>:7:17: error: constexpr variable 'x' must be initialized by a constant
expression
    constexpr X x = {};
                ^   ~~
<source>:7:17: note: pointer to subobject of 'x' is not a constant expression
<source>:7:17: note: declared here

But ideally we get some message about specifically 'head' pointing to 'storage'
and a fixup suggesting making the variable x static.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/96557] Diagnostics: Can you tell me why it's not a constant expression?
  2020-08-10 16:25 [Bug c++/96557] New: Diagnostics: Can you tell me why it's not a constant expression? barry.revzin at gmail dot com
@ 2020-08-10 16:40 ` mpolacek at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-08-10 16:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96557

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic
                 CC|                            |mpolacek at gcc dot gnu.org
   Last reconfirmed|                            |2020-08-10

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
That would be great to have.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-10 16:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10 16:25 [Bug c++/96557] New: Diagnostics: Can you tell me why it's not a constant expression? barry.revzin at gmail dot com
2020-08-10 16:40 ` [Bug c++/96557] " 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).