aboutsummaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/offsetof.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2023-01-18 08:49:45 -0500
committerAaron Ballman <aaron@aaronballman.com>2023-01-18 08:51:21 -0500
commite7300e75b51a7e7d4e81975b4be7a6c65f9a8286 (patch)
treede4e2e3f1ceaca35ae0e37c4417c66b97d9af7d6 /clang/test/SemaCXX/offsetof.cpp
parent63ba34f3fb752e0a60a78c21ee694e1064a870ab (diff)
downloadllvm-e7300e75b51a7e7d4e81975b4be7a6c65f9a8286.zip
llvm-e7300e75b51a7e7d4e81975b4be7a6c65f9a8286.tar.gz
llvm-e7300e75b51a7e7d4e81975b4be7a6c65f9a8286.tar.bz2
Diagnose extensions in 'offsetof'
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm made very clear that it is an UB having type definitions with in offsetof. Clang supports defining a type as the first argument as a conforming extension due to how many projects use the construct in C99 and earlier to calculate the alignment of a type. GCC also supports defining a type as the first argument. This adds extension warnings and documentation for the functionality Clang explicitly supports. Fixes #57065 Reverts the revert of 39da55e8f548a11f7dadefa73ea73d809a5f1729 Co-authored-by: Yingchi Long <i@lyc.dev> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Differential Revision: https://reviews.llvm.org/D133574
Diffstat (limited to 'clang/test/SemaCXX/offsetof.cpp')
-rw-r--r--clang/test/SemaCXX/offsetof.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/offsetof.cpp b/clang/test/SemaCXX/offsetof.cpp
index c4b288a..39ea380 100644
--- a/clang/test/SemaCXX/offsetof.cpp
+++ b/clang/test/SemaCXX/offsetof.cpp
@@ -83,3 +83,18 @@ struct Derived : virtual Base {
expected-error {{invalid application of 'offsetof' to a field of a virtual base}}
};
}
+
+int test_definition(void) {
+ return __builtin_offsetof(struct A // expected-error {{'A' cannot be defined in a type specifier}}
+ {
+ int a;
+ struct B // FIXME: error diagnostic message for nested definitions
+ // https://reviews.llvm.org/D133574
+ // fixme-error{{'A' cannot be defined in '__builtin_offsetof'}}
+ {
+ int c;
+ int d;
+ };
+ B x;
+ }, a);
+}