aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
diff options
context:
space:
mode:
authorNathan James <n.james93@hotmail.co.uk>2021-03-01 18:51:20 +0000
committerNathan James <n.james93@hotmail.co.uk>2021-03-01 18:51:50 +0000
commit8f9f7d02aaac98f8539158e05975e7acbbb58fcc (patch)
tree3dcad047797742950e65dc10f3b6d5199af2b6f8 /clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
parent18adbb86f9983fe7ec0506466a29fbd5a2cfa0d2 (diff)
downloadllvm-8f9f7d02aaac98f8539158e05975e7acbbb58fcc.zip
llvm-8f9f7d02aaac98f8539158e05975e7acbbb58fcc.tar.gz
llvm-8f9f7d02aaac98f8539158e05975e7acbbb58fcc.tar.bz2
[clang-tidy] Tweak misc-static-assert fix in c++17
If C++17 mode is enabled and the assert doesn't have a string literal, we can emit a static assert with no message in favour of one with an empty message. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D97313
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index 2d6504c..e9ea69aa 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -107,17 +107,16 @@ void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
FixItHints.push_back(
FixItHint::CreateReplacement(SourceRange(AssertLoc), "static_assert"));
- std::string StaticAssertMSG = ", \"\"";
if (AssertExprRoot) {
FixItHints.push_back(FixItHint::CreateRemoval(
SourceRange(AssertExprRoot->getOperatorLoc())));
FixItHints.push_back(FixItHint::CreateRemoval(
SourceRange(AssertMSG->getBeginLoc(), AssertMSG->getEndLoc())));
- StaticAssertMSG = (Twine(", \"") + AssertMSG->getString() + "\"").str();
+ FixItHints.push_back(FixItHint::CreateInsertion(
+ LastParenLoc, (Twine(", \"") + AssertMSG->getString() + "\"").str()));
+ } else if (!Opts.CPlusPlus17) {
+ FixItHints.push_back(FixItHint::CreateInsertion(LastParenLoc, ", \"\""));
}
-
- FixItHints.push_back(
- FixItHint::CreateInsertion(LastParenLoc, StaticAssertMSG));
}
diag(AssertLoc, "found assert() that could be replaced by static_assert()")