[modules] It's possible to merge into the pattern of a class template before we
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 22 Jan 2015 01:41:56 +0000 (01:41 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 22 Jan 2015 01:41:56 +0000 (01:41 +0000)
load the definition data from the declaration itself. In that case, merge
properly; don't assume the prior definition is the same as our own.

llvm-svn: 226761

clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/Modules/Inputs/merge-anon-in-template/a.h [new file with mode: 0644]
clang/test/Modules/Inputs/merge-anon-in-template/b.h [new file with mode: 0644]
clang/test/Modules/Inputs/merge-anon-in-template/c.h [new file with mode: 0644]
clang/test/Modules/Inputs/merge-anon-in-template/module.modulemap [new file with mode: 0644]
clang/test/Modules/merge-anon-in-template.cc [new file with mode: 0644]

index a783183..8c03b0b 100644 (file)
@@ -1457,9 +1457,13 @@ void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D) {
 
   ReadCXXDefinitionData(*DD, Record, Idx);
 
-  // If we're reading an update record, we might already have a definition for
-  // this record. If so, just merge into it.
-  if (D->DefinitionData.getNotUpdated()) {
+  // We might already have a definition for this record. This can happen either
+  // because we're reading an update record, or because we've already done some
+  // merging. Either way, just merge into it.
+  if (auto *CanonDD = D->DefinitionData.getNotUpdated()) {
+    if (CanonDD->Definition != DD->Definition)
+      Reader.MergedDeclContexts.insert(
+          std::make_pair(DD->Definition, CanonDD->Definition));
     MergeDefinitionData(D, *DD);
     return;
   }
diff --git a/clang/test/Modules/Inputs/merge-anon-in-template/a.h b/clang/test/Modules/Inputs/merge-anon-in-template/a.h
new file mode 100644 (file)
index 0000000..82540e3
--- /dev/null
@@ -0,0 +1,4 @@
+template<typename T> struct is_floating {
+  enum { value = 0 };
+  typedef int type;
+};
diff --git a/clang/test/Modules/Inputs/merge-anon-in-template/b.h b/clang/test/Modules/Inputs/merge-anon-in-template/b.h
new file mode 100644 (file)
index 0000000..87c053d
--- /dev/null
@@ -0,0 +1,2 @@
+#include "a.h"
+bool k = is_floating<int>::value;
diff --git a/clang/test/Modules/Inputs/merge-anon-in-template/c.h b/clang/test/Modules/Inputs/merge-anon-in-template/c.h
new file mode 100644 (file)
index 0000000..e0b9b0a
--- /dev/null
@@ -0,0 +1,6 @@
+template<typename T> struct is_floating {
+  enum { value = 0 };
+  typedef int type;
+};
+#include "b.h"
+bool n20 = is_floating<int>::value;
diff --git a/clang/test/Modules/Inputs/merge-anon-in-template/module.modulemap b/clang/test/Modules/Inputs/merge-anon-in-template/module.modulemap
new file mode 100644 (file)
index 0000000..77e0a89
--- /dev/null
@@ -0,0 +1,3 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
+module c { header "c.h" export * }
diff --git a/clang/test/Modules/merge-anon-in-template.cc b/clang/test/Modules/merge-anon-in-template.cc
new file mode 100644 (file)
index 0000000..6e4e6e0
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/merge-anon-in-template -verify %s
+// expected-no-diagnostics
+#include "a.h"
+#include "c.h"
+is_floating<int>::type t;