Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -315,6 +315,9 @@ def warn_redundant_parens_around_declarator : Warning< "redundant parentheses surrounding declarator">, InGroup>, DefaultIgnore; +def warn_misleading_var_type_decl : Warning< + "misleading variable declaration, supposed to be a pointer type instead ?">, + InGroup>; def note_additional_parens_for_variable_declaration : Note< "add a pair of parentheses to declare a variable">; def note_raii_guard_add_name : Note< Index: lib/Sema/SemaStmt.cpp =================================================================== --- lib/Sema/SemaStmt.cpp +++ lib/Sema/SemaStmt.cpp @@ -77,7 +77,26 @@ // If we have an invalid decl, just return an error. if (DG.isNull()) return StmtError(); - return new (Context) DeclStmt(DG, StartLoc, EndLoc); + DeclStmt *DS = new (Context) DeclStmt(DG, StartLoc, EndLoc); + if (DS) { + VarDecl *FirstVarDecl = nullptr; + for (auto *DI : DS->decls()) { + VarDecl *VD = dyn_cast(DI); + if (!VD) + continue; + + if (!FirstVarDecl) { + if (!VD->getType()->isPointerType()) + break; + FirstVarDecl = VD; + } else { + if (VD->getType() == FirstVarDecl->getType()->getPointeeType()) + Diag(VD->getLocation(), diag::warn_misleading_var_type_decl); + } + } + } + + return DS; } void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) { Index: test/Sema/misleading-var-type-decl.c =================================================================== --- test/Sema/misleading-var-type-decl.c +++ test/Sema/misleading-var-type-decl.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -verify -Wmisleading-declarations -fsyntax-only + +void test(void) { + int *a, b; // expected-warning {{misleading variable declaration, supposed to be a pointer type instead ?}} + int x, *y; + int *g, *h, *i, **j; + + for (int *a, b;;) { } // expected-warning {{misleading variable declaration, supposed to be a pointer type instead ?}} + for (int x, *y;;) { } + for (int *g, *h, *i, **j;;) { } +}