public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94772] New: [10 Regression] constructing constexpr variables fail with delegated constexpr constructors
@ 2020-04-26 11:59 gcc-bugs at marehr dot dialup.fu-berlin.de
  2020-04-26 13:32 ` [Bug c++/94772] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gcc-bugs at marehr dot dialup.fu-berlin.de @ 2020-04-26 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94772
           Summary: [10 Regression] constructing constexpr variables fail
                    with delegated constexpr constructors
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugs at marehr dot dialup.fu-berlin.de
  Target Milestone: ---

Hi gcc!

The following code does not compile with gcc10 anymore:

```c++
struct foo
{
    constexpr foo() noexcept = default;

    // fails with gcc10; commenting : foo{} out works with gcc10
    constexpr foo(int a, int b) : foo{} 
    {
        bar += a + b;
    }
    int bar{}; 
};

int main()
{
    constexpr foo bar{1, 2};
}
```
https://godbolt.org/z/brsFdo

All major compilers and gcc < 10 do support this, so I think this is a
regression.

```
> g++-git -std=c++2a

<source>: In function 'int main()':
<source>:15:27:   in 'constexpr' expansion of 'foo(1, 2)'
<source>:8:13: error: modifying a const object '((foo*)this)->foo::bar' is not
allowed in a constant expression
    8 |         bar += a + b;
      |         ~~~~^~~~~~~~
<source>:15:19: note: originally declared 'const' here
   15 |     constexpr foo bar{1, 2};
      |   
```

Thank you!

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

end of thread, other threads:[~2020-04-27 21:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-26 11:59 [Bug c++/94772] New: [10 Regression] constructing constexpr variables fail with delegated constexpr constructors gcc-bugs at marehr dot dialup.fu-berlin.de
2020-04-26 13:32 ` [Bug c++/94772] " jakub at gcc dot gnu.org
2020-04-26 19:55 ` ppalka at gcc dot gnu.org
2020-04-27  6:43 ` rguenth at gcc dot gnu.org
2020-04-27 21:15 ` cvs-commit at gcc dot gnu.org
2020-04-27 21:15 ` 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).