[cfe-commits] r148072 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/DeclSpec.h include/clang/Sema/Sema.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/Parser.cpp lib/Sema/AnalysisBasedWarnings.cpp l

Matthieu Monrocq matthieu.monrocq at gmail.com
Fri Jan 13 10:03:52 PST 2012


Hello Richard,

thank you very much for this, it looks really nice :)

I only have two tiny remarks:

--- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Thu Jan 12 17:53:29 2012
> @@ -756,6 +756,9 @@
>
>   bool findMacroSpelling(SourceLocation &loc, StringRef name);
>
> +  /// \brief Get a string to suggest for zero-initialization of a type.
> +  const char *getFixItZeroInitializerForType(QualType T) const;
> +
>

Why not use a StringRef here ?

It is meant to be passed to FixItHint::CreateInsertion anyway, which will
perform the conversion, and won't even benefit from __builtin_strlen to
deduce the length.

--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
> +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Thu Jan 12 17:53:29 2012
>
> [...]


> +  SourceLocation Loc = S.PP.getLocForEndOfToken(VD->getLocEnd());
> +  S.Diag(Loc, diag::note_var_fixit_add_initialization) <<
> VD->getDeclName()
> +    << FixItHint::CreateInsertion(Loc, Init);
> +  return true;
>  }
>
>

> --- cfe/trunk/lib/Sema/SemaFixItUtils.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaFixItUtils.cpp Thu Jan 12 17:53:29 2012
> @@ -158,3 +158,31 @@
>
>   return false;
>  }
> +
> +const char *Sema::getFixItZeroInitializerForType(QualType T) const {
> +  // Suggest 'nil' if it's defined and appropriate.
> +  if ((T->isObjCObjectPointerType() || T->isBlockPointerType()) &&
> +      PP.getMacroInfo(&getASTContext().Idents.get("nil")))
> +    return " = nil";
> +  if (T->isRealFloatingType())
> +    return " = 0.0";
> +  if (T->isBooleanType() && LangOpts.CPlusPlus)
> +    return " = false";
> +  if (T->isPointerType() || T->isMemberPointerType()) {
> +    if (LangOpts.CPlusPlus0x)
> +      return " = nullptr";
> +    // Check if 'NULL' is defined.
> +    else if (PP.getMacroInfo(&getASTContext().Idents.get("NULL")))
> +      return " = NULL";
>

Why not suggesting " = 0" here instead of letting the flow cascade ?


> +  }
> +  if (T->isEnumeralType())
> +    return 0;
> +  if (T->isScalarType())
> +    return " = 0";
> +  const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
> +  if (LangOpts.CPlusPlus0x && RD &&
> !RD->hasUserProvidedDefaultConstructor())
> +    return "{}";
> +  if (T->isAggregateType())
> +    return " = {}";
> +  return 0;
> +}
>
>
-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120113/8853b27c/attachment.html>


More information about the cfe-commits mailing list