diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-04-29 00:18:15 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-04-29 00:18:15 +0000 |
| commit | d17020676106cd77cd35d263c5549b605dad0225 (patch) | |
| tree | 0c226b716d4557190e486e71f490f08cbad50d14 /clang/test | |
| parent | a5a8f76cea106a8d766bd6d9351fd0f51ef46a2f (diff) | |
| download | bcm5719-llvm-d17020676106cd77cd35d263c5549b605dad0225.tar.gz bcm5719-llvm-d17020676106cd77cd35d263c5549b605dad0225.zip | |
Teach __builtin_offsetof to compute the offsets of members of base
classes, since we only warn (not error) on offsetof() for non-POD
types. We store the base path within the OffsetOfExpr itself, then
evaluate the offsets within the constant evaluator.
llvm-svn: 102571
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/SemaCXX/offsetof.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/offsetof.cpp b/clang/test/SemaCXX/offsetof.cpp index 4be97a948f6..47c3f22a0ed 100644 --- a/clang/test/SemaCXX/offsetof.cpp +++ b/clang/test/SemaCXX/offsetof.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -Winvalid-offsetof +// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s -Winvalid-offsetof struct NonPOD { virtual void f(); @@ -36,3 +36,20 @@ struct has_bitfields { }; int test3 = __builtin_offsetof(struct has_bitfields, j); // expected-error{{cannot compute offset of bit-field 'j'}} + +// offsetof referring to members of a base class. +struct Base1 { + int x; +}; + +struct Base2 { + int y; +}; + +struct Derived2 : public Base1, public Base2 { + int z; +}; + +int derived1[__builtin_offsetof(Derived2, x) == 0? 1 : -1]; +int derived2[__builtin_offsetof(Derived2, y) == 4? 1 : -1]; +int derived3[__builtin_offsetof(Derived2, z) == 8? 1 : -1]; |

