def : DiagGroup<"nonportable-cfstrings">;
def NonVirtualDtor : DiagGroup<"non-virtual-dtor">;
def OveralignedType : DiagGroup<"over-aligned">;
-def : DiagGroup<"old-style-cast">;
+def OldStyleCast : DiagGroup<"old-style-cast">;
def : DiagGroup<"old-style-definition">;
def OutOfLineDeclaration : DiagGroup<"out-of-line-declaration">;
def : DiagGroup<"overflow">;
def warn_cast_align : Warning<
"cast from %0 to %1 increases required alignment from %2 to %3">,
InGroup<CastAlign>, DefaultIgnore;
+def warn_old_style_cast : Warning<
+ "use of old-style cast">, InGroup<OldStyleCast>, DefaultIgnore;
// Separate between casts to void* and non-void* pointers.
// Some APIs use (abuse) void* for something like a user context,
CastExpr = Result.take();
}
+ if (getLangOpts().CPlusPlus && !castType->isVoidType())
+ Diag(CastExpr->getLocStart(), diag::warn_old_style_cast)
+ << SourceRange(LParenLoc, RParenLoc);
+
return BuildCStyleCastExpr(LParenLoc, castTInfo, RParenLoc, CastExpr);
}
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify -Wold-style-cast %s
+
+void test1() {
+ long x = (long)12; // expected-warning {{use of old-style cast}}
+ (long)x; // expected-warning {{use of old-style cast}} expected-warning {{expression result unused}}
+ (void**)x; // expected-warning {{use of old-style cast}} expected-warning {{expression result unused}}
+ long y = static_cast<long>(12);
+ (void)y;
+ typedef void VOID;
+ (VOID)y;
+}