[all-commits] [llvm/llvm-project] 9d739e: [Clang] Implement CWG2351 `void{}` (#78060)

Mital Ashok via All-commits all-commits at lists.llvm.org
Wed Aug 21 01:09:30 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9d739e54f4506bf9bd220c5d65f710b86a39f6d5
      https://github.com/llvm/llvm-project/commit/9d739e54f4506bf9bd220c5d65f710b86a39f6d5
  Author: Mital Ashok <mital at mitalashok.co.uk>
  Date:   2024-08-21 (Wed, 21 Aug 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/AST/ExprCXX.h
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/lib/Sema/SemaInit.cpp
    M clang/test/CXX/drs/cwg23xx.cpp
    M clang/test/SemaCXX/attr-annotate.cpp
    M clang/test/SemaCXX/cxx2a-explicit-bool.cpp
    M clang/test/SemaCXX/sugared-auto.cpp
    M clang/www/cxx_dr_status.html

  Log Message:
  -----------
  [Clang] Implement CWG2351 `void{}` (#78060)

Per [CWG2351](https://wg21.link/CWG2351), allow `void{}`, treated the
same as `void()`: a prvalue expression of type `void` that performs no
initialization.

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 'T':'void' functional cast to T <ToVoid>
`-InitListExpr 'void'
// using T = const void;
CXXFunctionalCastExpr 'void' functional cast to T <ToVoid>
`-InitListExpr 'void'
```

As for `void()`/`T() [T = const void]`, that looked like
`CXXScalarValueInitExpr 'void'` and is unchanged after this.

For reference, C++98 [5.2.3p2] says:

> The expression `T()`, where `T` is a simple-type-specifier (7.1.5.2)
for a non-array complete object type or the (possibly cv-qualified) void
type, creates an rvalue of the specified type, whose value is determined
by default-initialization (8.5; no initialization is done for the
`void()` case). [*Note:* if `T` is a non-class type that is
*cv-qualified*, the `cv-qualifiers` are ignored when determining the
type of the resulting rvalue (3.10). ]

Though it is a bit of a misnomer that, for `T = void`,
`CXXScalarValueInitExpr` does not perform value initialization, it would
be a breaking change to change the AST node for `void()`, so I simply
reworded the doc comment.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list