]> granicus.if.org Git - clang/commitdiff
When producing -Wuninitialized Fix-Its for pointers, prefer " = NULL"
authorDouglas Gregor <dgregor@apple.com>
Sat, 2 Jul 2011 00:59:18 +0000 (00:59 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 2 Jul 2011 00:59:18 +0000 (00:59 +0000)
over "= 0". Fixes <rdar://problem/9714386>.

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

lib/Sema/AnalysisBasedWarnings.cpp

index 9efae6103a4a957cfcaf110286ced604c0346a32..e560ef8a5c0ee414340c3987f19c17746eb7bcb1 100644 (file)
@@ -486,7 +486,8 @@ static void SuggestInitializationFixit(Sema &S, const VarDecl *VD) {
   const char *initialization = 0;
   QualType VariableTy = VD->getType().getCanonicalType();
 
-  if (VariableTy->getAs<ObjCObjectPointerType>()) {
+  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";