[PATCH] D113838: Sema: Don't erroneously reject `void{}`

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 14 08:19:37 PST 2021

aaronpuchert added a subscriber: Tyker.
aaronpuchert added a comment.

CC @Tyker for the changes to `SemaCXX/attr-annotate.cpp`.

Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:5848-5849
 def err_illegal_initializer_type : Error<"illegal initializer type %0">;
+def err_init_list_void_nonempty : Error<
+  "initializer list for 'void' must be empty">;
 def ext_init_list_type_narrowing : ExtWarn<
Might also consider it a narrowing conversion. But I can't find the standard specifically calling it that.

Comment at: clang/test/CXX/expr/expr.post/expr.type.conv/p2.cpp:12
+void brace_list_nonempty() {
+  return void{1}; // expected-error {{initializer list for 'void' must be empty}}
With parantheses this is (correctly) allowed:

> If the initializer is a parenthesized single expression, the type conversion expression is equivalent to the corresponding cast expression.


> Any expression can be explicitly converted to type cv `void`, in which case it becomes a discarded-value expression ([expr.prop]).

Not sure if we need a test for that.

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list