================
@@ -1600,12 +1600,25 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
     return ExprError(Diag(TyBeginLoc, diag::err_init_for_function_type)
                        << Ty << FullRange);
 
-  // C++17 [expr.type.conv]p2:
-  //   If the type is cv void and the initializer is (), the expression is a
-  //   prvalue of the specified type that performs no initialization.
-  if (!Ty->isVoidType() &&
-      RequireCompleteType(TyBeginLoc, ElemTy,
-                          diag::err_invalid_incomplete_type_use, FullRange))
+  // C++17 [expr.type.conv]p2, per DR2351:
+  //   If the type is cv void and the initializer is () or {}, the expression 
is
+  //   a prvalue of the specified type that performs no initialization.
+  if (Ty->isVoidType()) {
----------------
MitalAshok wrote:

[[expr.type.conv]p2](https://wg21.link/expr.type.conv#2) reads 
"`T(expression-list)` or `T braced-init-list` is a cast expression, a prvalue 
`void`, or direct-initialized from the initializer". So when we encounter 
`void()` or `void{}`, we shouldn't actually use initialization semantics.

Previously, `void()` worked because 
https://github.com/llvm/llvm-project/blob/2d09ac4037415ab0044ad508aae2ff8b2559a9d8/clang/lib/Sema/SemaInit.cpp#L6255-L6260
 made it a value initialization by accident, and we allowed value initializing 
void

I've now added an assertion for `void` in `TryValueInitialization` because you 
shouldn't actually be able to get there, since there's no standard way to call 
for the value-intialization of `void`

https://github.com/llvm/llvm-project/pull/78060
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to