Bring ASTReader and Writer into sync for the case where a canonical template speciali...
authorAxel Naumann <Axel.Naumann@cern.ch>
Mon, 1 Oct 2012 07:34:47 +0000 (07:34 +0000)
committerAxel Naumann <Axel.Naumann@cern.ch>
Mon, 1 Oct 2012 07:34:47 +0000 (07:34 +0000)
The easiest way out is to store whether the decl was canonical at the time of writing.
Add test.

llvm-svn: 164927

clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/Modules/Inputs/redecl-merge-left.h
clang/test/Modules/Inputs/redecl-merge-right.h
clang/test/Modules/Inputs/redecl-merge-top.h
clang/test/Modules/redecl-merge.m

index c9788a3..843893d 100644 (file)
@@ -1395,14 +1395,17 @@ void ASTDeclReader::VisitClassTemplateSpecializationDecl(
                                                      TemplArgs.size());
   D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
   D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
-  
-  if (D->isCanonicalDecl()) { // It's kept in the folding set.
+
+  bool writtenAsCanonicalDecl = Record[Idx++];
+  if (writtenAsCanonicalDecl) {
     ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
-    if (ClassTemplatePartialSpecializationDecl *Partial
-                       = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
-      CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
-    } else {
-      CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
+    if (D->isCanonicalDecl()) { // It's kept in the folding set.
+      if (ClassTemplatePartialSpecializationDecl *Partial
+                        = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
+       CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
+      } else {
+        CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
+      }
     }
   }
 }
index 7122bca..0f9bb38 100644 (file)
@@ -1106,6 +1106,7 @@ void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
   Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
   Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
   Record.push_back(D->getSpecializationKind());
+  Record.push_back(D->isCanonicalDecl());
 
   if (D->isCanonicalDecl()) {
     // When reading, we'll add it to the folding set of the following template. 
index b3a7ba8..4bdd015 100644 (file)
@@ -82,6 +82,12 @@ extern double var3;
 template<typename T> class Vector;
 
 template<typename T> class Vector;
+
+template<typename T> class List;
+template<> class List<bool> {
+public:
+  void push_back(int);
+};
 #endif
 
 // Make sure this doesn't introduce an ambiguity-creating 'id' at the
index de7aa08..6953276 100644 (file)
@@ -83,6 +83,12 @@ template<typename T> class Vector {
 public:
   void push_back(const T&);
 };
+
+template<typename T> class List;
+template<> class List<bool> {
+public:
+  void push_back(int);
+};
 #endif
 
 int ONE;
index 519254c..7053936 100644 (file)
@@ -17,4 +17,9 @@ struct S2;
 
 #ifdef __cplusplus
 template<typename T> class Vector;
+
+template<typename T> class List {
+public:
+  void push_back(T);
+};
 #endif
index d7930ac..0e5cd4a 100644 (file)
@@ -150,6 +150,9 @@ id<P3> p3;
 void testVector() {
   Vector<int> vec_int;
   vec_int.push_back(0);
+
+  List<bool> list_bool;
+  list_bool.push_back(false);
 }
 #endif