[PATCH] D63128: Fixed google-readability-casting test to work in c++17
Shaurya Gupta via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 11 03:07:26 PDT 2019
SureYeaah created this revision.
SureYeaah added reviewers: gribozavr, hokein.
Herald added a project: clang.
Fixed google-readability-casting.cpp to get tests working in c++17
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63128
Files:
clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
Index: clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
+++ clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s google-readability-casting %t
+// RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t
// FIXME: Fix the checker to work in C++17 mode.
bool g() { return false; }
Index: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -86,6 +86,10 @@
bool FnToFnCast =
isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten);
+ const bool ConstructorCast = !CastExpr->getTypeAsWritten().hasQualifiers() &&
+ DestTypeAsWritten->isRecordType() &&
+ !DestTypeAsWritten->isElaboratedTypeSpecifier();
+
if (CastExpr->getCastKind() == CK_NoOp && !FnToFnCast) {
// Function pointer/reference casts may be needed to resolve ambiguities in
// case of overloaded functions, so detection of redundant casts is trickier
@@ -144,19 +148,19 @@
Diag << CastType;
ReplaceWithCast((CastType + "<" + DestTypeString + ">").str());
};
-
+ auto ReplaceWithConstructorCall = [&]() {
+ Diag << "constructor call syntax";
+ // FIXME: Validate DestTypeString, maybe.
+ ReplaceWithCast(DestTypeString.str());
+ };
// Suggest appropriate C++ cast. See [expr.cast] for cast notation semantics.
switch (CastExpr->getCastKind()) {
case CK_FunctionToPointerDecay:
ReplaceWithNamedCast("static_cast");
return;
case CK_ConstructorConversion:
- if (!CastExpr->getTypeAsWritten().hasQualifiers() &&
- DestTypeAsWritten->isRecordType() &&
- !DestTypeAsWritten->isElaboratedTypeSpecifier()) {
- Diag << "constructor call syntax";
- // FIXME: Validate DestTypeString, maybe.
- ReplaceWithCast(DestTypeString.str());
+ if (ConstructorCast) {
+ ReplaceWithConstructorCall();
} else {
ReplaceWithNamedCast("static_cast");
}
@@ -176,6 +180,10 @@
ReplaceWithNamedCast("const_cast");
return;
}
+ if (ConstructorCast) {
+ ReplaceWithConstructorCall();
+ return;
+ }
if (DestType->isReferenceType()) {
QualType Dest = DestType.getNonReferenceType();
QualType Source = SourceType.getNonReferenceType();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63128.204002.patch
Type: text/x-patch
Size: 2627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190611/817c9c27/attachment.bin>
More information about the cfe-commits
mailing list