mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-04 16:41:43 +00:00
[Clang] Handle static_assert messages with an expression started by a literal
Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D156597
This commit is contained in:
parent
31850318f7
commit
4d494e76d0
@ -1016,10 +1016,23 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (isTokenStringLiteral())
|
||||
AssertMessage = ParseUnevaluatedStringLiteralExpression();
|
||||
else if (getLangOpts().CPlusPlus26)
|
||||
bool ParseAsExpression = false;
|
||||
if (getLangOpts().CPlusPlus26) {
|
||||
for (unsigned I = 0;; ++I) {
|
||||
const Token &T = GetLookAheadToken(I);
|
||||
if (T.is(tok::r_paren))
|
||||
break;
|
||||
if (T.isNot(tok::string_literal)) {
|
||||
ParseAsExpression = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ParseAsExpression)
|
||||
AssertMessage = ParseConstantExpressionInExprEvalContext();
|
||||
else if (isTokenStringLiteral())
|
||||
AssertMessage = ParseUnevaluatedStringLiteralExpression();
|
||||
else {
|
||||
Diag(Tok, diag::err_expected_string_literal)
|
||||
<< /*Source='static_assert'*/ 1;
|
||||
|
@ -65,6 +65,10 @@ struct string_view {
|
||||
}
|
||||
};
|
||||
|
||||
constexpr string_view operator+(auto, string_view S) {
|
||||
return S;
|
||||
}
|
||||
|
||||
constexpr const char g_[] = "long string";
|
||||
|
||||
template <typename T, int S>
|
||||
@ -79,6 +83,11 @@ struct array {
|
||||
};
|
||||
|
||||
static_assert(false, string_view("test")); // expected-error {{static assertion failed: test}}
|
||||
static_assert(false, "Literal" + string_view("test")); // expected-error {{static assertion failed: test}}
|
||||
static_assert(false, L"Wide Literal" + string_view("test")); // expected-error {{static assertion failed: test}}
|
||||
static_assert(false, "Wild" "Literal" "Concatenation" + string_view("test")); // expected-error {{static assertion failed: test}}
|
||||
static_assert(false, "Wild" "Literal" L"Concatenation" + string_view("test")); // expected-error {{static assertion failed: test}}
|
||||
static_assert(false, "Wild" u"Literal" L"Concatenation" + string_view("test")); // expected-error {{unsupported non-standard concatenation of string literals}}
|
||||
static_assert(false, string_view("😀")); // expected-error {{static assertion failed: 😀}}
|
||||
static_assert(false, string_view(0, nullptr)); // expected-error {{static assertion failed:}}
|
||||
static_assert(false, string_view(1, "ABC")); // expected-error {{static assertion failed: A}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user