cor3ntin created this revision. Herald added a project: All. cor3ntin requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D156597 Files: clang/lib/Parse/ParseDeclCXX.cpp clang/test/SemaCXX/static-assert-cxx26.cpp Index: clang/test/SemaCXX/static-assert-cxx26.cpp =================================================================== --- clang/test/SemaCXX/static-assert-cxx26.cpp +++ clang/test/SemaCXX/static-assert-cxx26.cpp @@ -65,6 +65,10 @@ } }; +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 @@ }; 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}} Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ clang/lib/Parse/ParseDeclCXX.cpp @@ -1016,10 +1016,23 @@ return nullptr; } - if (isTokenStringLiteral()) - AssertMessage = ParseUnevaluatedStringLiteralExpression(); - else if (getLangOpts().CPlusPlus26) + bool ParseAsExression = 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)) { + ParseAsExression = true; + break; + } + } + } + + if(ParseAsExression) AssertMessage = ParseConstantExpressionInExprEvalContext(); + else if (isTokenStringLiteral()) + AssertMessage = ParseUnevaluatedStringLiteralExpression(); else { Diag(Tok, diag::err_expected_string_literal) << /*Source='static_assert'*/ 1;
Index: clang/test/SemaCXX/static-assert-cxx26.cpp =================================================================== --- clang/test/SemaCXX/static-assert-cxx26.cpp +++ clang/test/SemaCXX/static-assert-cxx26.cpp @@ -65,6 +65,10 @@ } }; +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 @@ }; 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}} Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ clang/lib/Parse/ParseDeclCXX.cpp @@ -1016,10 +1016,23 @@ return nullptr; } - if (isTokenStringLiteral()) - AssertMessage = ParseUnevaluatedStringLiteralExpression(); - else if (getLangOpts().CPlusPlus26) + bool ParseAsExression = 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)) { + ParseAsExression = true; + break; + } + } + } + + if(ParseAsExression) AssertMessage = ParseConstantExpressionInExprEvalContext(); + else if (isTokenStringLiteral()) + AssertMessage = ParseUnevaluatedStringLiteralExpression(); else { Diag(Tok, diag::err_expected_string_literal) << /*Source='static_assert'*/ 1;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits