aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-04-06 22:24:14 +0000
committerJohn McCall <rjmccall@apple.com>2010-04-06 22:24:14 +0000
commit209acbd6d0c1b4444eb8c1682717753e1cbe38de (patch)
tree05a24c0410ee04ea08f192f0920470d3d8c6886b /lib/Sema/SemaStmt.cpp
parent68b9a599dda7c422a417dfdc330adb5a880eb0e5 (diff)
Devote a special diagnostic to the typo
(void*) someFunction(5, 10, 15, 20); where the cast is presumably meant to be to 'void'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100574 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r--lib/Sema/SemaStmt.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 791de8c2b9..0c55cf5c5c 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -20,6 +20,7 @@
#include "clang/AST/ExprObjC.h"
#include "clang/AST/StmtObjC.h"
#include "clang/AST/StmtCXX.h"
+#include "clang/AST/TypeLoc.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/STLExtras.h"
@@ -126,6 +127,22 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
return;
}
}
+
+ // Diagnose "(void*) blah" as a typo for "(void) blah".
+ else if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E)) {
+ TypeSourceInfo *TI = CE->getTypeInfoAsWritten();
+ QualType T = TI->getType();
+
+ // We really do want to use the non-canonical type here.
+ if (T == Context.VoidPtrTy) {
+ PointerTypeLoc TL = cast<PointerTypeLoc>(TI->getTypeLoc());
+
+ Diag(Loc, diag::warn_unused_voidptr)
+ << FixItHint::CreateRemoval(TL.getStarLoc());
+ return;
+ }
+ }
+
Diag(Loc, DiagID) << R1 << R2;
}