Skip to content

Invalid consteval constructor invocation does not cause an error #51593

@stbergmann

Description

@stbergmann
Bugzilla Link 52251
Version trunk
OS Linux
CC @AaronBallman,@zygoloid

Extended Description

At least with Clang 13 and recent Clang 14 trunk,

$ cat test.cc
struct S {
consteval S() {}
int a;
};
S s2;

$ clang++ -std=c++20 -fsyntax-only test.cc

erroneously succeeds, while e.g. with GCC 11 it fails with

$ g++ -std=c++20 -fsyntax-only test.cc
test.cc:5:3: error: ‘S()’ is not a constant expression
5 | S s2;
| ^~
test.cc:5:3: error: ‘s2.S::S()’ is not a constant expression because it refers to an incompletely initialized variable

(I think this is different from bug 51560, as the initialization of s2 here asks for default-initialization via the S() constructor.)

Metadata

Metadata

Assignees

Labels

accepts-invalidbugzillaIssues migrated from bugzillac++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyconstevalC++20 consteval

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions