[PATCH] D158532: Anonymous unions should be transparent wrt `[[clang::trivial_abi]]`.
Ćukasz Anforowicz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 22 10:57:16 PDT 2023
lukasza created this revision.
lukasza added a reviewer: gribozavr2.
lukasza added a project: clang.
Herald added a subscriber: mstorsjo.
Herald added a project: All.
lukasza requested review of this revision.
Herald added a subscriber: cfe-commits.
This is a reland of https://reviews.llvm.org/D155895.
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]] S {
S(S&& other) {}
S& operator=(S&& other) { return *this; }
~S() {}
union { Trivial field; };
};
static_assert(__is_trivially_relocatable(S), "");
Before the fix Clang would warn that 'trivial_abi' is disallowed on 'S'
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 that contain
fields with a non-trivial copy constructors or move constructors.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158532
Files:
clang/include/clang/Basic/LangOptions.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/attr-trivial-abi.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158532.552435.patch
Type: text/x-patch
Size: 13032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230822/98605a2c/attachment.bin>
More information about the cfe-commits
mailing list