[PATCH] D89065: [clang] Tweaked fixit for static assert with no message
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 10 18:12:44 PDT 2020
njames93 updated this revision to Diff 297434.
njames93 added a comment.
FixIt now properly generated
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89065/new/
https://reviews.llvm.org/D89065
Files:
clang/lib/Parse/ParseDeclCXX.cpp
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -858,6 +858,16 @@
DeclFromDeclSpec);
}
+static FixItHint getStaticAssertNoMessageFixIt(const Expr *AssertExpr,
+ SourceLocation EndExprLoc) {
+ if (const auto *BO = llvm::dyn_cast_or_null<BinaryOperator>(AssertExpr)) {
+ if (BO->getOpcode() == BO_LAnd &&
+ llvm::isa<StringLiteral>(BO->getRHS()->IgnoreImpCasts()))
+ return FixItHint::CreateReplacement(BO->getOperatorLoc(), ",");
+ }
+ return FixItHint::CreateInsertion(EndExprLoc, ", \"\"");
+}
+
/// ParseStaticAssertDeclaration - Parse C++0x or C11 static_assert-declaration.
///
/// [C++0x] static_assert-declaration:
@@ -894,12 +904,11 @@
ExprResult AssertMessage;
if (Tok.is(tok::r_paren)) {
- Diag(Tok, getLangOpts().CPlusPlus17
- ? diag::warn_cxx14_compat_static_assert_no_message
- : diag::ext_static_assert_no_message)
- << (getLangOpts().CPlusPlus17
- ? FixItHint()
- : FixItHint::CreateInsertion(Tok.getLocation(), ", \"\""));
+ if (getLangOpts().CPlusPlus17)
+ Diag(Tok, diag::warn_cxx14_compat_static_assert_no_message);
+ else
+ Diag(Tok, diag::ext_static_assert_no_message)
+ << getStaticAssertNoMessageFixIt(AssertExpr.get(), Tok.getLocation());
} else {
if (ExpectAndConsume(tok::comma)) {
SkipUntil(tok::semi);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89065.297434.patch
Type: text/x-patch
Size: 1592 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201011/8a4591e9/attachment.bin>
More information about the cfe-commits
mailing list