]> granicus.if.org Git - clang/commitdiff
Read/write C++0x static_assert for PCH.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 22 Jul 2010 17:28:12 +0000 (17:28 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 22 Jul 2010 17:28:12 +0000 (17:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109123 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclCXX.h
lib/Frontend/PCHReaderDecl.cpp
lib/Frontend/PCHWriterDecl.cpp
test/PCH/cxx-static_assert.cpp [new file with mode: 0644]
test/PCH/cxx-static_assert.h [new file with mode: 0644]

index 41474ab21e32cf49a53edbc49bf07ae3d6d103b0..9cea17e8acb469d7f7a71ad2f76eb5504c97e964 100644 (file)
@@ -2249,6 +2249,8 @@ public:
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(StaticAssertDecl *D) { return true; }
   static bool classofKind(Kind K) { return K == StaticAssert; }
+
+  friend class PCHDeclReader;
 };
 
 /// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
index 7297fefcb26ec351a2480071d655cafd14363a72..d1f8b3aae94d1e96c287b7837fe1309152289e86 100644 (file)
@@ -1035,7 +1035,9 @@ void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
 }
 
 void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
-  assert(false && "cannot read StaticAssertDecl");
+  VisitDecl(D);
+  D->AssertExpr = Reader.ReadExpr();
+  D->Message = cast<StringLiteral>(Reader.ReadExpr());
 }
 
 std::pair<uint64_t, uint64_t>
@@ -1412,7 +1414,7 @@ Decl *PCHReader::ReadDeclRecord(unsigned Index) {
     D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
     break;
   case pch::DECL_STATIC_ASSERT:
-    assert(false && "cannot read StaticAssertDecl");
+    D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
     break;
 
   case pch::DECL_OBJC_METHOD:
index 122bd3dea1a750c9166dcea555c1ead95bbe74ea..f6c6cde1577c36760896170f6c6b903c8c5b0ddf 100644 (file)
@@ -989,7 +989,10 @@ void PCHDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
 }
 
 void PCHDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
-  assert(false && "cannot write StaticAssertDecl");
+  VisitDecl(D);
+  Writer.AddStmt(D->getAssertExpr());
+  Writer.AddStmt(D->getMessage());
+  Code = pch::DECL_STATIC_ASSERT;
 }
 
 /// \brief Emit the DeclContext part of a declaration context decl.
diff --git a/test/PCH/cxx-static_assert.cpp b/test/PCH/cxx-static_assert.cpp
new file mode 100644 (file)
index 0000000..3440921
--- /dev/null
@@ -0,0 +1,11 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/cxx-static_assert.h -verify -std=c++0x %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c++-header -std=c++0x -emit-pch -o %t %S/cxx-static_assert.h
+// RUN: %clang_cc1 -include-pch %t -verify -std=c++0x %s 
+
+// expected-error {{static_assert failed "N is not 2!"}}
+
+T<1> t1; // expected-note {{in instantiation of template class 'T<1>' requested here}}
+T<2> t2;
diff --git a/test/PCH/cxx-static_assert.h b/test/PCH/cxx-static_assert.h
new file mode 100644 (file)
index 0000000..ba41ab8
--- /dev/null
@@ -0,0 +1,9 @@
+// Header for PCH test cxx-static_assert.cpp
+
+
+
+
+
+template<int N> struct T {
+    static_assert(N == 2, "N is not 2!");
+};