]> granicus.if.org Git - clang/commitdiff
Separate the logic for issuing the initialization fixit hint from the
authorChandler Carruth <chandlerc@gmail.com>
Tue, 5 Apr 2011 18:18:08 +0000 (18:18 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 5 Apr 2011 18:18:08 +0000 (18:18 +0000)
diagnostic emission. The fixit hint, when suggested, typically has
nothing to do with the nature or form of the reference.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128899 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AnalysisBasedWarnings.cpp

index bd5416f5f7617127fc4b5e946e9d3cb9662cb7f5..a649ff067e877f34f068921938229627dfa903f8 100644 (file)
@@ -411,8 +411,7 @@ public:
 }
 
 static void DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,
-                                     const Expr *E, bool &fixitIssued,
-                                     bool isAlwaysUninit) {
+                                     const Expr *E, bool isAlwaysUninit) {
   bool isSelfInit = false;
 
   if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
@@ -465,6 +464,10 @@ static void DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,
     S.Diag(VD->getLocStart(), diag::note_uninit_var_def)
       << VD->getDeclName();
 
+}
+
+static void SuggestInitializationFixit(Sema &S, const VarDecl *VD,
+                                       bool &fixitIssued) {
   // Only report the fixit once.
   if (fixitIssued)
     return;
@@ -552,9 +555,12 @@ public:
       // a stable ordering.
       std::sort(vec->begin(), vec->end(), SLocSort());
       
-      for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve; ++vi)
-        DiagnoseUninitializedUse(S, vd, vi->first, fixitIssued,
+      for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve;
+           ++vi) {
+        DiagnoseUninitializedUse(S, vd, vi->first,
                                  /*isAlwaysUninit=*/vi->second);
+        SuggestInitializationFixit(S, vd, fixitIssued);
+      }
 
       delete vec;
     }