llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.12k stars 11.61k forks source link

Defaulted default union constructor incorrectly deleted #56814

Open kparzysz-quic opened 2 years ago

kparzysz-quic commented 2 years ago
struct NT {
  NT(); // non-trivial constructor
};

union U {
  U() = default;
  NT x;
  int y = 0;  // default member initializer
};
$ clang++ -c union1.cc  -std=c++17
union1.cc:6:3: warning: explicitly defaulted default constructor is implicitly deleted [-Wdefaulted-function-deleted]
  U() = default;
  ^
union1.cc:7:6: note: default constructor of 'U' is implicitly deleted because variant field 'x' has a non-trivial default constructor
  NT x;
     ^
1 warning generated.

This seems to contravene 15.1.5:

15.1 Constructors [...]

  1. A defaulted default constructor for class X is defined as deleted if:
    • X is a union that has a variant member with a non-trivial default constructor and no variant member of X has a default member initializer,

[...]

This issue may be related to https://github.com/llvm/llvm-project/issues/56313.

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-frontend