[cfe-commits] r109123 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp test/PCH/cxx-static_assert.cpp test/PCH/cxx-static_assert.h
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Jul 22 10:28:12 PDT 2010
Author: akirtzidis
Date: Thu Jul 22 12:28:12 2010
New Revision: 109123
URL: http://llvm.org/viewvc/llvm-project?rev=109123&view=rev
Log:
Read/write C++0x static_assert for PCH.
Added:
cfe/trunk/test/PCH/cxx-static_assert.cpp
cfe/trunk/test/PCH/cxx-static_assert.h
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=109123&r1=109122&r2=109123&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Jul 22 12:28:12 2010
@@ -2249,6 +2249,8 @@
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
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=109123&r1=109122&r2=109123&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Thu Jul 22 12:28:12 2010
@@ -1035,7 +1035,9 @@
}
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 @@
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:
Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=109123&r1=109122&r2=109123&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Thu Jul 22 12:28:12 2010
@@ -989,7 +989,10 @@
}
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.
Added: cfe/trunk/test/PCH/cxx-static_assert.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-static_assert.cpp?rev=109123&view=auto
==============================================================================
--- cfe/trunk/test/PCH/cxx-static_assert.cpp (added)
+++ cfe/trunk/test/PCH/cxx-static_assert.cpp Thu Jul 22 12:28:12 2010
@@ -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;
Added: cfe/trunk/test/PCH/cxx-static_assert.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-static_assert.h?rev=109123&view=auto
==============================================================================
--- cfe/trunk/test/PCH/cxx-static_assert.h (added)
+++ cfe/trunk/test/PCH/cxx-static_assert.h Thu Jul 22 12:28:12 2010
@@ -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!");
+};
More information about the cfe-commits
mailing list