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
* [Bug c++/94772] [10 Regression] constructing constexpr variables fail with delegated constexpr constructors
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 ` jakub at gcc dot gnu.org
2020-04-26 19:55 ` ppalka at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-04-26 13:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94772
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-04-26
Status|UNCONFIRMED |NEW
Target Milestone|--- |10.0
Ever confirmed|0 |1
CC| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r10-7490-g76f09260b7eccd6c3cfa3dcf3c22897fe12a8065
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94772] [10 Regression] constructing constexpr variables fail with delegated constexpr constructors
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-26 19:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94772
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC| |ppalka at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Created attachment 48378
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48378&action=edit
patch in testing
I am testing the attached patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94772] [10 Regression] constructing constexpr variables fail with delegated constexpr constructors
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
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-27 6:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94772
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Priority|P3 |P1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94772] [10 Regression] constructing constexpr variables fail with delegated constexpr constructors
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
` (2 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-27 21:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94772
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:64da1b761db248f4f0d2235a6055c025fbbc94eb
commit r10-7996-g64da1b761db248f4f0d2235a6055c025fbbc94eb
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Apr 27 17:06:35 2020 -0400
c++: Delegating constructor in constexpr init [PR94772]
In the first testcase below, the call to the target constructor foo{} from
foo's
delegating constructor is encoded as the INIT_EXPR
*(struct foo *) this = AGGR_INIT_EXPR <4, __ct_comp, D.2140, ...>;
During initialization of the variable 'bar', we prematurely set
TREE_READONLY on
bar's CONSTRUCTOR in two places before the outer delegating constructor has
returned: first, at the end of cxx_eval_call_expression after evaluating
the RHS
of the above INIT_EXPR, and second, at the end of cxx_eval_store_expression
after having finished evaluating the above INIT_EXPR. This then prevents
the
rest of the outer delegating constructor from mutating 'bar'.
This (hopefully minimally risky) patch makes cxx_eval_call_expression
refrain
from setting TREE_READONLY when evaluating the target constructor of a
delegating constructor. It also makes cxx_eval_store_expression refrain
from
setting TREE_READONLY when the object being initialized is "*this', on the
basis
that it should be the responsibility of the routine that set 'this' in the
first
place to set the object's TREE_READONLY appropriately.
gcc/cp/ChangeLog:
PR c++/94772
* constexpr.c (cxx_eval_call_expression): Don't set new_obj if
we're
evaluating the target constructor of a delegating constructor.
(cxx_eval_store_expression): Don't set TREE_READONLY if the LHS of
the
INIT_EXPR is '*this'.
gcc/testsuite/ChangeLog:
PR c++/94772
* g++.dg/cpp1y/constexpr-tracking-const23.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const24.C: New test.
* g++.dg/cpp1y/constexpr-tracking-const25.C: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94772] [10 Regression] constructing constexpr variables fail with delegated constexpr constructors
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
` (3 preceding siblings ...)
2020-04-27 21:15 ` cvs-commit at gcc dot gnu.org
@ 2020-04-27 21:15 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-27 21:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94772
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed.
^ 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).