llvm / llvm-project

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

empty union type should not be literal #53806

Open seanbaxter opened 2 years ago

seanbaxter commented 2 years ago
union u1 { };
static_assert(!__is_literal_type(u1));

https://eel.is/c++draft/basic#types.general-10.5.3

if it is a union, at least one of its non-static data members is of non-volatile literal type, and

tru commented 2 years ago

Can you explain where you find this reference in the source so we know who to direct this issue to.

seanbaxter commented 2 years ago

I don't know anything about the clang source. It simply appears not to be conformant in this instance

msebor commented 2 years ago

I'm not an expert anymore but I agree that strict reading of the C++ standard does seem to imply that an empty struct or union type is not a literal type. At the same time, all compilers on Godbolt I tried (GCC, ICC, and Visual C++) fail the assertion the same way Clang does, and note 4 at the end of paragraph 10 suggests the intent might actually be to treat such types as literal:

[ Note: A literal type is one for which it might be possible to create an object within a constant expression. It is not a guarantee that it is possible to create such an object, nor is it a guarantee that any object of that type will usable in a constant expression. — end note]

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-frontend

shafik commented 2 years ago

If I am reading the proposed resolution to DR2598 I believe it proposes to allow empty unions to be literal type:

is an aggregate type (9.4.2 [dcl.init.aggr]) for which that type (if it is a union) or each of its anonymous union members (otherwise) either has at least one variant member of non-volatile literal type or has no variant members, or

CC @zygoloid