public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102000] New: Defaulted consteval default constructor that performs no initialization is not rejected
@ 2021-08-20 14:41 johelegp at gmail dot com
2021-08-20 14:42 ` [Bug c++/102000] " redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: johelegp at gmail dot com @ 2021-08-20 14:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102000
Bug ID: 102000
Summary: Defaulted consteval default constructor that performs
no initialization is not rejected
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: johelegp at gmail dot com
CC: johelegp at gmail dot com
Target Milestone: ---
See https://godbolt.org/z/Te3nY7YeW and discussion at
https://cpplang.slack.com/archives/C21PKDHSL/p1629467874085000.
```C++
struct X{
int i;
consteval X() = default;
};
constexpr void f() {
[[maybe_unused]] X x_f;
}
int main () {
[[maybe_unused]] X x_main;
[]() consteval { f(); }();
}
```
```
An immediate invocation shall be a constant expression. --
https://eel.is/c++draft/expr.const#13.sentence-3
Lots of wording in between...
2 A variable or temporary object o is constant-initialized if
(2.1) either it has an initializer or its default-initialization results in
some initialization being performed, and
-- https://eel.is/c++draft/expr.const#2
7 To default-initialize an object of type T means:
(7.3) Otherwise, no initialization is performed.
-- https://eel.is/c++draft/dcl.init.general#7
```
```
[W]hether it's defaulted or not, `i` is uninitialized so it should reject both.
```
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102000] Defaulted consteval default constructor that performs no initialization is not rejected
2021-08-20 14:41 [Bug c++/102000] New: Defaulted consteval default constructor that performs no initialization is not rejected johelegp at gmail dot com
@ 2021-08-20 14:42 ` redi at gcc dot gnu.org
2021-08-20 15:02 ` johelegp at gmail dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-20 14:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102000
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-08-20
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102000] Defaulted consteval default constructor that performs no initialization is not rejected
2021-08-20 14:41 [Bug c++/102000] New: Defaulted consteval default constructor that performs no initialization is not rejected johelegp at gmail dot com
2021-08-20 14:42 ` [Bug c++/102000] " redi at gcc dot gnu.org
@ 2021-08-20 15:02 ` johelegp at gmail dot com
2021-08-23 9:54 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: johelegp at gmail dot com @ 2021-08-20 15:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102000
--- Comment #1 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
Can https://bugs.llvm.org/show_bug.cgi?id=51560 be fixed as part of this?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102000] Defaulted consteval default constructor that performs no initialization is not rejected
2021-08-20 14:41 [Bug c++/102000] New: Defaulted consteval default constructor that performs no initialization is not rejected johelegp at gmail dot com
2021-08-20 14:42 ` [Bug c++/102000] " redi at gcc dot gnu.org
2021-08-20 15:02 ` johelegp at gmail dot com
@ 2021-08-23 9:54 ` redi at gcc dot gnu.org
2021-08-23 21:43 ` johelegp at gmail dot com
2022-12-03 18:22 ` hstong at ca dot ibm.com
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-23 9:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102000
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Johel Ernesto Guerrero Peña from comment #1)
> Can https://bugs.llvm.org/show_bug.cgi?id=51560 be fixed as part of this?
That is:
struct X{
int i;
consteval X() = default;
// consteval X() {}
};
int main () {
auto x = X();
(void)x;
}
Which is also accepts-invalid
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102000] Defaulted consteval default constructor that performs no initialization is not rejected
2021-08-20 14:41 [Bug c++/102000] New: Defaulted consteval default constructor that performs no initialization is not rejected johelegp at gmail dot com
` (2 preceding siblings ...)
2021-08-23 9:54 ` redi at gcc dot gnu.org
@ 2021-08-23 21:43 ` johelegp at gmail dot com
2022-12-03 18:22 ` hstong at ca dot ibm.com
4 siblings, 0 replies; 6+ messages in thread
From: johelegp at gmail dot com @ 2021-08-23 21:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102000
--- Comment #3 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
https://bugs.llvm.org/show_bug.cgi?id=51560#c1 points out
> I'm not sure what you think the problem is here. The constructor isn't getting called; see http://eel.is/c++draft/dcl.init.general#8 .
It seems to me that they are right and the example above is well-formed.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102000] Defaulted consteval default constructor that performs no initialization is not rejected
2021-08-20 14:41 [Bug c++/102000] New: Defaulted consteval default constructor that performs no initialization is not rejected johelegp at gmail dot com
` (3 preceding siblings ...)
2021-08-23 21:43 ` johelegp at gmail dot com
@ 2022-12-03 18:22 ` hstong at ca dot ibm.com
4 siblings, 0 replies; 6+ messages in thread
From: hstong at ca dot ibm.com @ 2022-12-03 18:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102000
Hubert Tong <hstong at ca dot ibm.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hstong at ca dot ibm.com
--- Comment #4 from Hubert Tong <hstong at ca dot ibm.com> ---
(In reply to Johel Ernesto Guerrero Peña from comment #3)
> https://bugs.llvm.org/show_bug.cgi?id=51560#c1 points out
> > I'm not sure what you think the problem is here. The constructor isn't getting called; see http://eel.is/c++draft/dcl.init.general#8 .
> It seems to me that they are right and the example above is well-formed.
That depends on what "the semantic constraints for default-initialization are
checked" means.
(In reply to Johel Ernesto Guerrero Peña from comment #0)
> ```
> An immediate invocation shall be a constant expression. --
> https://eel.is/c++draft/expr.const#13.sentence-3
>
> Lots of wording in between...
>
> 2 A variable or temporary object o is constant-initialized if
> (2.1) either it has an initializer or its default-initialization results
> in some initialization being performed, and
> -- https://eel.is/c++draft/expr.const#2
> 7 To default-initialize an object of type T means:
> (7.3) Otherwise, no initialization is performed.
> -- https://eel.is/c++draft/dcl.init.general#7
> ```
That wording would be relevant for a similar case involving `constinit`. Here,
the relevant wording is in 7.7 [expr.const] paragraph 12 (and the uninitialized
`int` is fine with the current wording). The example needs to be changed to use
pointers:
```
struct A {
consteval A() = default;
private:
int *m;
};
struct B {
consteval B() = default;
private:
int *m, *n = 0;
};
void f() {
A a; // GCC accepts this despite pointer with indeterminate value
B b; // GCC rejects this
}
```
So it seems GCC just doesn't do certain checking when the constructor is
trivial.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-12-03 18:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20 14:41 [Bug c++/102000] New: Defaulted consteval default constructor that performs no initialization is not rejected johelegp at gmail dot com
2021-08-20 14:42 ` [Bug c++/102000] " redi at gcc dot gnu.org
2021-08-20 15:02 ` johelegp at gmail dot com
2021-08-23 9:54 ` redi at gcc dot gnu.org
2021-08-23 21:43 ` johelegp at gmail dot com
2022-12-03 18:22 ` hstong at ca dot ibm.com
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).