]> granicus.if.org Git - clang/commitdiff
AST: Properly calculate the linkage of a IndirectFieldDecl
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 10 Dec 2014 22:58:14 +0000 (22:58 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 10 Dec 2014 22:58:14 +0000 (22:58 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223975 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Decl.cpp
test/SemaCXX/anonymous-union.cpp

index a937fdf09209400fa12f0232ccd0c8e6d964dc3c..3e398ae91788e9be86f62eb878ea6938e5fbce26 100644 (file)
@@ -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<IndirectFieldDecl>(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<IndirectFieldDecl>(D) && "Didn't expect an IndirectFieldDecl!");
   assert(!isa<FieldDecl>(D) && "Didn't expect a FieldDecl!");
 
   if (D->isInAnonymousNamespace()) {
index fde27b049d88209440e316c39a70ba5634987a0c..3b568fd8704f16d20a1219f616583b5daad80fed 100644 (file)
@@ -84,6 +84,10 @@ static union {
   float float_val2;
 };
 
+void PR21858() {
+  void int_val2();
+}
+
 void f() {
   int_val2 = 0;
   float_val2 = 0.0;