]> granicus.if.org Git - clang/commitdiff
[ODRHash] Revert r305104 - Skip inline namespaces when hashing.
authorRichard Trieu <rtrieu@google.com>
Sat, 1 Jul 2017 02:00:05 +0000 (02:00 +0000)
committerRichard Trieu <rtrieu@google.com>
Sat, 1 Jul 2017 02:00:05 +0000 (02:00 +0000)
Test inline namespaces and handle them in the ODR hash again.

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

lib/AST/ODRHash.cpp
lib/AST/StmtProfile.cpp
test/Modules/odr_hash.cpp

index 0e44a12257cb0fee8972c693ecd554b7b0ee44d2..3f66e58eb868c7cc11b1d1d0c0560316ef4e4d83 100644 (file)
@@ -82,25 +82,13 @@ void ODRHash::AddDeclarationName(DeclarationName Name) {
 }
 
 void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
-  // Unlike the other pointer handling functions, allow null pointers here.
-  if (!NNS) {
-    AddBoolean(false);
-    return;
+  assert(NNS && "Expecting non-null pointer.");
+  const auto *Prefix = NNS->getPrefix();
+  AddBoolean(Prefix);
+  if (Prefix) {
+    AddNestedNameSpecifier(Prefix);
   }
-
-  // Skip inlined namespaces.
   auto Kind = NNS->getKind();
-  if (Kind == NestedNameSpecifier::Namespace) {
-    if (NNS->getAsNamespace()->isInline()) {
-      return AddNestedNameSpecifier(NNS->getPrefix());
-    }
-  }
-
-  AddBoolean(true);
-
-  // Process prefix
-  AddNestedNameSpecifier(NNS->getPrefix());
-
   ID.AddInteger(Kind);
   switch (Kind) {
   case NestedNameSpecifier::Identifier:
@@ -441,7 +429,10 @@ public:
   }
 
   void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
-    Hash.AddNestedNameSpecifier(NNS);
+    Hash.AddBoolean(NNS);
+    if (NNS) {
+      Hash.AddNestedNameSpecifier(NNS);
+    }
   }
 
   void AddIdentifierInfo(const IdentifierInfo *II) {
index 99a25f3425268585ec9e7953b6feee02c2f38e11..f1fbe2806b5d09c3ebeda1afc1ffbca0a5cd4f8f 100644 (file)
@@ -186,7 +186,10 @@ namespace {
       Hash.AddTemplateName(Name);
     }
     void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
-      Hash.AddNestedNameSpecifier(NNS);
+      ID.AddBoolean(NNS);
+      if (NNS) {
+        Hash.AddNestedNameSpecifier(NNS);
+      }
     }
   };
 }
index 3b213971696c24343d89a3f1ac2a09ef1b05d034..6e01e989a3742a911e8db2e10b8a14305a0af2b9 100644 (file)
@@ -968,6 +968,24 @@ S9 s9;
 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'P9::I' (aka 'int')}}
 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
 #endif
+
+namespace N10 {
+#if defined(FIRST)
+inline namespace A { struct X {}; }
+struct S10 {
+  A::X x;
+};
+#elif defined(SECOND)
+inline namespace B { struct X {}; }
+struct S10 {
+  B::X x;
+};
+#else
+S10 s10;
+// expected-error@second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}}
+// expected-note@first.h:* {{declaration of 'x' does not match}}
+#endif
+}
 }
 
 namespace TemplateSpecializationType {