diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-04-28 22:43:14 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-04-28 22:43:14 +0000 |
commit | 29d2fd56b5eeeb52f7fdbdd232229e570c30d62b (patch) | |
tree | 07af568652a1e01db4e4795e1ed8fa289cd74a92 | |
parent | 802898158be3f53e2090ccc380f58ae213bf872e (diff) |
Fix template instantiation for __builtin_offfsetof expressions that refer to members of anonymous structs/unions
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102551 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/TreeTransform.h | 3 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-expr-5.cpp | 16 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 17f6553d0d..4e32897df6 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -4219,6 +4219,9 @@ TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { case Node::Identifier: Comp.isBrackets = false; Comp.U.IdentInfo = ON.getFieldName(); + if (!Comp.U.IdentInfo) + continue; + break; } diff --git a/test/SemaTemplate/instantiate-expr-5.cpp b/test/SemaTemplate/instantiate-expr-5.cpp index 916c4f9493..6cdedda4d8 100644 --- a/test/SemaTemplate/instantiate-expr-5.cpp +++ b/test/SemaTemplate/instantiate-expr-5.cpp @@ -19,4 +19,20 @@ namespace PR5880 { struct B { ArrayOfHasM a; }; A<B> x; A<HasM> x2; // expected-note{{in instantiation of}} + + template<typename T> + struct AnonymousUnion { + union { + int i; + float f; + }; + }; + + template<typename T> + void test_anon_union() { + int array1[__builtin_offsetof(AnonymousUnion<T>, f) == 0? 1 : -1]; + int array2[__builtin_offsetof(AnonymousUnion<int>, f) == 0? 1 : -1]; + } + + template void test_anon_union<int>(); } |