InGroup<DiagGroup<"uninitialized-experimental">>, DefaultIgnore;
def note_var_is_uninit : Note<
"variable %0 is possibly uninitialized when used here">;
+def note_var_fixit_add_initialization : Note<
+ "add initialization to silence this warning">;
def err_init_incomplete_type : Error<"initialization of incomplete type %0">;
def err_temp_copy_no_viable : Error<
#include "clang/Sema/AnalysisBasedWarnings.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Preprocessor.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/ExprObjC.h"
S.Diag(vd->getLocStart(), diag::warn_var_is_uninit)
<< vd->getDeclName() << vd->getSourceRange();
-
+
// Sort the uses by their SourceLocations. While not strictly
// guaranteed to produce them in line/column order, this will provide
// a stable ordering.
S.Diag(dr->getLocStart(), diag::note_var_is_uninit)
<< vd->getDeclName() << dr->getSourceRange();
}
+
+ // Suggest possible initialization (if any).
+ const char *initialization = 0;
+ QualType vdTy = vd->getType();
+
+ if (vdTy->getAs<ObjCObjectPointerType>()) {
+ initialization = " = nil";
+ }
+ else if (vdTy->getAs<PointerType>()) {
+ initialization = " = 0";
+ }
+
+ if (initialization) {
+ SourceLocation loc = S.PP.getLocForEndOfToken(vd->getLocEnd());
+ S.Diag(loc, diag::note_var_fixit_add_initialization)
+ << FixItHint::CreateInsertion(loc, initialization);
+ }
+
delete vec;
}
delete uses;
void test17() {
// Don't warn multiple times about the same uninitialized variable
// along the same path.
- int *x; // expected-warning{{use of uninitialized variable 'x'}}
+ int *x; // expected-warning{{use of uninitialized variable 'x'}} expected-note{{add initialization to silence this warning}}
*x = 1; // expected-note{{variable 'x' is possibly uninitialized when used here}}
*x = 1; // no-warning
}