[all-commits] [llvm/llvm-project] bddaa3: Anonymous unions should be transparent wrt `[[clan...
Dmitri Gribenko via All-commits
all-commits at lists.llvm.org
Mon Aug 7 11:31:04 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: bddaa35177861545fc329123e55b6a3b34549507
https://github.com/llvm/llvm-project/commit/bddaa35177861545fc329123e55b6a3b34549507
Author: Dmitri Gribenko <gribozavr at gmail.com>
Date: 2023-08-07 (Mon, 07 Aug 2023)
Changed paths:
M clang/include/clang/Basic/LangOptions.h
M clang/lib/Frontend/CompilerInvocation.cpp
M clang/lib/Sema/SemaDeclCXX.cpp
M clang/test/SemaCXX/attr-trivial-abi.cpp
Log Message:
-----------
Anonymous unions should be transparent wrt `[[clang::trivial_abi]]`.
Anonymous unions should be transparent wrt `[[clang::trivial_abi]]`.
Consider the test input below:
```
struct [[clang::trivial_abi]] Trivial {
Trivial() {}
Trivial(Trivial&& other) {}
Trivial& operator=(Trivial&& other) { return *this; }
~Trivial() {}
};
static_assert(__is_trivially_relocatable(Trivial), "");
struct [[clang::trivial_abi]] S2 {
S2(S2&& other) {}
S2& operator=(S2&& other) { return *this; }
~S2() {}
union { Trivial field; };
};
static_assert(__is_trivially_relocatable(S2), "");
```
Before the fix Clang would warn that 'trivial_abi' is disallowed on 'S2'
because it has a field of a non-trivial class type (the type of the
anonymous union is non-trivial, because it doesn't have the
`[[clang::trivial_abi]]` attribute applied to it). Consequently, before
the fix the `static_assert` about `__is_trivially_relocatable` would
fail.
Note that `[[clang::trivial_abi]]` cannot be applied to the anonymous
union, because Clang warns that 'trivial_abi' is disallowed on '(unnamed
union at ...)' because its copy constructors and move constructors are
all deleted. Also note that it is impossible to provide copy nor move
constructors for anonymous unions and structs.
Reviewed By: gribozavr2
Differential Revision: https://reviews.llvm.org/D155895
More information about the All-commits
mailing list