diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-05 23:20:05 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-05 23:20:05 +0000 |
commit | 0cc323c6bed7206f9743a9775ec8d9cb90655f9c (patch) | |
tree | 5d4fea5c36daf0a866976076a48a17674fbb32f2 | |
parent | a99f874bf2ade1e32f0feda7d5b8211171440f02 (diff) |
static_assert: Allow any string-literal as the message, not just a character
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
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 8 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/p4-0x.cpp | 2 |
4 files changed, 10 insertions, 4 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 816956051c..36c302fb86 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 983bd7ee15..978b2b362d 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -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; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b603b64bda..abcaf98357 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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)) diff --git a/test/CXX/dcl.dcl/p4-0x.cpp b/test/CXX/dcl.dcl/p4-0x.cpp index 9af2d2176f..31d49127e7 100644 --- a/test/CXX/dcl.dcl/p4-0x.cpp +++ b/test/CXX/dcl.dcl/p4-0x.cpp @@ -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!\""}} |