From 8ba44264e05fe0012ecfb7bac28b171b5a50dde3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 2 Jul 2011 00:59:18 +0000 Subject: [PATCH] When producing -Wuninitialized Fix-Its for pointers, prefer " = NULL" over "= 0". Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134302 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/AnalysisBasedWarnings.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 9efae6103a..e560ef8a5c 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -486,7 +486,8 @@ static void SuggestInitializationFixit(Sema &S, const VarDecl *VD) { const char *initialization = 0; QualType VariableTy = VD->getType().getCanonicalType(); - if (VariableTy->getAs()) { + if (VariableTy->isObjCObjectPointerType() || + VariableTy->isBlockPointerType()) { // Check if 'nil' is defined. if (S.PP.getMacroInfo(&S.getASTContext().Idents.get("nil"))) initialization = " = nil"; @@ -499,6 +500,13 @@ static void SuggestInitializationFixit(Sema &S, const VarDecl *VD) { initialization = " = false"; else if (VariableTy->isEnumeralType()) return; + else if (VariableTy->isPointerType() || VariableTy->isMemberPointerType()) { + // Check if 'NULL' is defined. + if (S.PP.getMacroInfo(&S.getASTContext().Idents.get("NULL"))) + initialization = " = NULL"; + else + initialization = " = 0"; + } else if (VariableTy->isScalarType()) initialization = " = 0";