From 29d2fd56b5eeeb52f7fdbdd232229e570c30d62b Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 28 Apr 2010 22:43:14 +0000 Subject: [PATCH] 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 --- lib/Sema/TreeTransform.h | 3 +++ test/SemaTemplate/instantiate-expr-5.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) 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::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 x; A x2; // expected-note{{in instantiation of}} + + template + struct AnonymousUnion { + union { + int i; + float f; + }; + }; + + template + void test_anon_union() { + int array1[__builtin_offsetof(AnonymousUnion, f) == 0? 1 : -1]; + int array2[__builtin_offsetof(AnonymousUnion, f) == 0? 1 : -1]; + } + + template void test_anon_union(); } -- 2.40.0