[PATCH] D52791: [Diagnostics] Check for misleading variable declarations

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 2 11:01:37 PDT 2018


erik.pilkington added a comment.

Thanks for working on this!



================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:318-320
+def warn_misleading_var_type_decl : Warning<
+  "misleading variable declaration, supposed to be a pointer type instead ?">,
+  InGroup<DiagGroup<"misleading-declarations">>;
----------------
I think this should really be off by default, this is a stylistic warning that would be really noisy for existing projects. Also, I think the text might be better spelled as "declaring a variable of type %0; did you mean to declare a pointer?".  Also, -Wmisleading-declarations doesn't really describe what this warning diagnoses. This is C, so there is plenty of ways to write a misleading declaration ;). Maybe -Wmisleading-pointer-declarator?


================
Comment at: lib/Sema/SemaStmt.cpp:81
+  DeclStmt *DS = new (Context) DeclStmt(DG, StartLoc, EndLoc);
+  if (DS) {
+    VarDecl *FirstVarDecl = nullptr;
----------------
The null check here is redundant, new (Context) should never return nullptr.


https://reviews.llvm.org/D52791





More information about the cfe-commits mailing list