-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid consteval constructor invocation does not cause an error #51593
Comments
This is an issue. We currently fail to check immediate invocations of constructors in other interesting ways as well:
|
@llvm/issue-subscribers-c-20 |
@llvm/issue-subscribers-clang-frontend |
I've been looking into this issue pretty deeply lately and have some new thoughts.
After the adoption of P1331R2 in C++20, this code becomes valid because static initialization kicks in before constant evaluation does, so However, the example I gave in my comment is still code that should not be accepted in the |
That said, I think the fix for the second case will end up breaking the first case so that we wind up diagnosing in Clang the same as GCC, ICC, and MSCV all currently diagnose. One of the problems we have is that we do not add an expression evaluation context for the translation unit itself, so we don't issue any constant expression diagnostics for globals currently. Another problem is that we don't seem to model static initialization as being zero initialization in the constant expression evaluator, and so we consider the members of a statically initialized structure as being uninitialized. |
1c55f05 addresses part of the issues here. |
Extended Description
At least with Clang 13 and recent Clang 14 trunk,
erroneously succeeds, while e.g. with GCC 11 it fails with
(I think this is different from bug 51560, as the initialization of s2 here asks for default-initialization via the S() constructor.)
The text was updated successfully, but these errors were encountered: