[clang] [SemaCXX] Implement CWG2351 `void{}` (PR #78060)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 29 16:31:57 PDT 2024


zygoloid wrote:

> Note that the AST for the expression `T{}` looks like:
> 
> ```
> // using T = int;
> CXXFunctionalCastExpr 'T':'int' functional cast to T <NoOp>
> `-InitListExpr 'T':'int'
> // using T = const int;
> CXXFunctionalCastExpr 'int' functional cast to T <NoOp>
> `-InitListExpr 'int'
> // using T = void;
> CXXFunctionalCastExpr 'void' functional cast to T <NoOp>
> `-InitListExpr 'void'
> // using T = const void;
> CXXFunctionalCastExpr 'void' functional cast to T <NoOp>
> `-InitListExpr 'void'
> ```
> 
> (Since the `InitListExpr` already has `void` before anything is done, the type doesn't need to be adjusted)

Nonetheless, I think it'd be more reasonable to use `CK_ToVoid` here rather than `CK_NoOp`. The `void` type for the `InitListExpr` is just a placeholder and not meant to mean that it's a real expression of type `void`. (We really ought to use a better placeholder there, so we can print the type out as `<braced initializer list>` instead of as `void` in diagnostics.)

https://github.com/llvm/llvm-project/pull/78060


More information about the cfe-commits mailing list