summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-01-15 09:10:25 +0100
committerStephan Bergmann <sbergman@redhat.com>2018-01-15 09:10:25 +0100
commita409d32e7f6fc09e041079d6dbc3c927497adfed (patch)
tree625a2e225b780a36034376c744cd70212ebaa624 /compilerplugins
parent17fbc3f8fd4ae04fbb0cb94514a41ee3b6bc7274 (diff)
More loplugin:cstylecast
...also warn about the remaining cases of C-style casts (other than idiomatic cast to void) Change-Id: I274be61ad038fc41ac470fc07ea703a0f071f456
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/cstylecast.cxx14
1 files changed, 8 insertions, 6 deletions
diff --git a/compilerplugins/clang/cstylecast.cxx b/compilerplugins/clang/cstylecast.cxx
index f09ce81a2987..ba89c1aa02b5 100644
--- a/compilerplugins/clang/cstylecast.cxx
+++ b/compilerplugins/clang/cstylecast.cxx
@@ -232,16 +232,15 @@ bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) {
if( expr->getCastKind() == CK_ToVoid ) {
return true;
}
- // ignore integral-type conversions for now, there is insufficient agreement about
- // the merits of C++ style casting in this case
- if( expr->getCastKind() == CK_IntegralCast ) {
- return true;
- }
if (isSharedCAndCppCode(expr->getLocStart())) {
return true;
}
char const * perf = nullptr;
- if( expr->getCastKind() == CK_NoOp ) {
+ if( expr->getCastKind() == CK_IntegralCast ) {
+ if (rewriteArithmeticCast(expr, &perf)) {
+ return true;
+ }
+ } else if( expr->getCastKind() == CK_NoOp ) {
if (!((expr->getSubExpr()->getType()->isPointerType()
&& expr->getType()->isPointerType())
|| expr->getTypeAsWritten()->isReferenceType()))
@@ -530,6 +529,9 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const *
while (compiler.getSourceManager().isMacroBodyExpansion(third)
&& compiler.getSourceManager().isAtStartOfImmediateMacroExpansion(third, &third))
{}
+ } else if (compiler.getSourceManager().isMacroBodyExpansion(fourth)) {
+ while (compiler.getSourceManager().isMacroArgExpansion(third)
+ && compiler.getSourceManager().isAtStartOfImmediateMacroExpansion(third, &third)) {}
}
if (!third.isMacroID()) {
while (compiler.getSourceManager().isMacroBodyExpansion(fourth)