]> granicus.if.org Git - clang/commitdiff
static_assert: Allow any string-literal as the message, not just a character
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 5 Mar 2012 23:20:05 +0000 (23:20 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 5 Mar 2012 23:20:05 +0000 (23:20 +0000)
string literal, and adjust the diagnostic code to match. This also causes us
to escape any control characters in the message.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Parse/ParseDeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp
test/CXX/dcl.dcl/p4-0x.cpp

index 816956051c2934ccc2995c725e4d2189f81615d1..36c302fb8640ef12b242f2924b7a2654c735c616 100644 (file)
@@ -688,7 +688,7 @@ def warn_unimplemented_protocol_method : Warning<
 // C++ declarations
 def err_static_assert_expression_is_not_constant : Error<
   "static_assert expression is not an integral constant expression">;
-def err_static_assert_failed : Error<"static_assert failed \"%0\"">;
+def err_static_assert_failed : Error<"static_assert failed %0">;
 
 def warn_inline_namespace_reopened_noninline : Warning<
   "inline namespace cannot be re-opened as a non-inline namespace">;
index 983bd7ee1523661b23ab3338929515284fc60739..978b2b362d1dfb23589e95b133446e4503170058 100644 (file)
@@ -610,7 +610,7 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){
   if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi))
     return 0;
 
-  if (Tok.isNot(tok::string_literal)) {
+  if (!isTokenStringLiteral()) {
     Diag(Tok, diag::err_expected_string_literal);
     SkipUntil(tok::semi);
     return 0;
index b603b64bda9ff062fdaf03430a9d95ff5282a9c1..abcaf983572d5af97856af00e991699daf639d0d 100644 (file)
@@ -9646,9 +9646,13 @@ Decl *Sema::ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
           /*AllowFold=*/false).isInvalid())
       return 0;
 
-    if (!Cond)
+    if (!Cond) {
+      llvm::SmallString<256> MsgBuffer;
+      llvm::raw_svector_ostream Msg(MsgBuffer);
+      AssertMessage->printPretty(Msg, Context, 0, getPrintingPolicy());
       Diag(StaticAssertLoc, diag::err_static_assert_failed)
-        << AssertMessage->getString() << AssertExpr->getSourceRange();
+        << Msg.str() << AssertExpr->getSourceRange();
+    }
   }
 
   if (DiagnoseUnexpandedParameterPack(AssertExpr, UPPC_StaticAssertExpression))
index 9af2d2176f9ec6e36f850cf29dceb4c092b6fdb8..31d49127e7a77e88fc5152e438b332af4d577d33 100644 (file)
@@ -17,3 +17,5 @@ static_assert(S(true), "");
 static_assert(S(false), "not so fast"); // expected-error {{not so fast}}
 static_assert(T(), "");
 static_assert(U(), ""); // expected-error {{ambiguous}}
+
+static_assert(false, L"\x14hi" "!" R"x(")x"); // expected-error {{static_assert failed L"\024hi!\""}}