[PATCH] D113838: Sema: Don't erroneously reject `void{}`
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 7 15:14:57 PST 2022
rsmith added a comment.
This is CWG issue 2351. Please add a corresponding test to `tests/CXX/drs/dr23xx.cpp`.
================
Comment at: clang/lib/Sema/SemaInit.cpp:1311-1319
+ } else if (DeclType->isVoidType()) {
+ // [expr.type.conv]p2: Otherwise, if the type is cv void and the
+ // initializer is () or {} (after pack expansion, if any), the expression
+ // is a prvalue of type void that performs no initialization.
+ if (IList->getNumInits() > 0) {
+ if (!VerifyOnly)
+ SemaRef.Diag(IList->getBeginLoc(), diag::err_init_list_void_nonempty);
----------------
Hm, this seems like the wrong place for this check, given the wording -- the language rule is specific to functional casts, and shouldn't apply to initialization of `void`-typed objects in general -- but perhaps it's the best place we have (and I think we deal with the `void()` case here in SemaInit too). Please at least make sure that we still properly reject things like:
```
void f() {
return {};
}
```
We also need to decide whether to accept the compound-literal form of this:
```
void g() {
(void){};
}
```
GCC trunk does, but I'm not sure whether that's intentional or an oversight. We certainly shouldn't accept that (without a diagnostic, at least) in C.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113838/new/
https://reviews.llvm.org/D113838
More information about the cfe-commits
mailing list