From 18fac3b1dd8026953dbac543c85696cd9388ba42 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 10 Dec 2014 22:58:14 +0000 Subject: [PATCH] AST: Properly calculate the linkage of a IndirectFieldDecl getLVForNamespaceScopeDecl believed that it wasn't possible for it to ever see an IndirectFieldDecl. However, this can occur when determining whether or not something is a redeclaration of a member of an anonymous static union. This fixes PR21858. llvm-svn: 223975 --- clang/lib/AST/Decl.cpp | 7 +++++-- clang/test/SemaCXX/anonymous-union.cpp | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index a937fdf..3e398ae 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -619,9 +619,12 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, // Explicitly declared static. if (Function->getCanonicalDecl()->getStorageClass() == SC_Static) return LinkageInfo(InternalLinkage, DefaultVisibility, false); + } else if (const auto *IFD = dyn_cast(D)) { + // - a data member of an anonymous union. + const VarDecl *VD = IFD->getVarDecl(); + assert(VD && "Expected a VarDecl in this IndirectFieldDecl!"); + return getLVForNamespaceScopeDecl(VD, computation); } - // - a data member of an anonymous union. - assert(!isa(D) && "Didn't expect an IndirectFieldDecl!"); assert(!isa(D) && "Didn't expect a FieldDecl!"); if (D->isInAnonymousNamespace()) { diff --git a/clang/test/SemaCXX/anonymous-union.cpp b/clang/test/SemaCXX/anonymous-union.cpp index fde27b04..3b568fd 100644 --- a/clang/test/SemaCXX/anonymous-union.cpp +++ b/clang/test/SemaCXX/anonymous-union.cpp @@ -84,6 +84,10 @@ static union { float float_val2; }; +void PR21858() { + void int_val2(); +} + void f() { int_val2 = 0; float_val2 = 0.0; -- 2.7.4