<br><br><div class="gmail_quote">Le 13 janvier 2012 20:39, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>></span> a écrit :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Fri, January 13, 2012 18:03, Matthieu Monrocq wrote:<br>
> thank you very much for this, it looks really nice :)<br>
<br>
</div>Thanks!<br>
<div class="im"><br>
> I only have two tiny remarks:<br>
><br>
>> --- cfe/trunk/include/clang/Sema/Sema.h (original)<br>
>> +++ cfe/trunk/include/clang/Sema/Sema.h Thu Jan 12 17:53:29 2012<br>
>> @@ -756,6 +756,9 @@<br>
>><br>
>><br>
>> bool findMacroSpelling(SourceLocation &loc, StringRef name);<br>
>><br>
>> +  /// \brief Get a string to suggest for zero-initialization of a type.<br>
>> +  const char *getFixItZeroInitializerForType(QualType T) const;<br>
>> +<br>
><br>
> Why not use a StringRef here ?<br>
><br>
> It is meant to be passed to FixItHint::CreateInsertion anyway, which will<br>
> perform the conversion, and won't even benefit from __builtin_strlen to deduce<br>
> the length.<br>
<br>
</div>Conversion to StringRef makes both call sites slightly uglier, because<br>
StringRef doesn't have a contextual conversion to bool. More generally, it's<br>
not clear to me whether StringRef is intended to semantically distinguish null<br>
and non-null length-0 values. While the current implementation of this<br>
function never returns a non-null empty string, previous drafts of it did, and<br>
such a return value would mean something different from a null return.<br>
<br></blockquote><div><br>Ah indeed, I didn't consider the null/empty distinction and I am not sure whether StringRef is intended to cope with nullity.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

The performance difference is interesting, but this function is only intended<br>
to be used on very cold paths, so I don't find it compelling.<br>
<div><div class="h5"><br>
>> --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)<br>
>> +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Thu Jan 12 17:53:29 2012<br>
>><br>
>><br>
>> [...]<br>
>><br>
><br>
><br>
>> +  SourceLocation Loc = S.PP.getLocForEndOfToken(VD->getLocEnd());<br>
>> +  S.Diag(Loc, diag::note_var_fixit_add_initialization) <<<br>
>> VD->getDeclName()<br>
>> +    << FixItHint::CreateInsertion(Loc, Init);<br>
>> +  return true;<br>
>> }<br>
>><br>
>><br>
>><br>
><br>
>> --- cfe/trunk/lib/Sema/SemaFixItUtils.cpp (original)<br>
>> +++ cfe/trunk/lib/Sema/SemaFixItUtils.cpp Thu Jan 12 17:53:29 2012<br>
>> @@ -158,3 +158,31 @@<br>
>><br>
>><br>
>> return false; }<br>
>> +<br>
>> +const char *Sema::getFixItZeroInitializerForType(QualType T) const {<br>
>> +  // Suggest 'nil' if it's defined and appropriate.<br>
>> +  if ((T->isObjCObjectPointerType() || T->isBlockPointerType()) &&<br>
>> +      PP.getMacroInfo(&getASTContext().Idents.get("nil")))<br>
>> +    return " = nil";<br>
>> +  if (T->isRealFloatingType())<br>
>> +    return " = 0.0";<br>
>> +  if (T->isBooleanType() && LangOpts.CPlusPlus)<br>
>> +    return " = false";<br>
>> +  if (T->isPointerType() || T->isMemberPointerType()) {<br>
>> +    if (LangOpts.CPlusPlus0x)<br>
>> +      return " = nullptr";<br>
>> +    // Check if 'NULL' is defined.<br>
>> +    else if (PP.getMacroInfo(&getASTContext().Idents.get("NULL")))<br>
>> +      return " = NULL";<br>
>><br>
>><br>
><br>
> Why not suggesting " = 0" here instead of letting the flow cascade ?<br>
<br>
</div></div>The same question applies to Obj-C pointers, block pointers and _Bool. The<br>
intent of this arrangement was: if the type is a scalar type, produce " = 0"<br>
unless we know of something better.<br>
<br>
Does r148135 look better to you?<br>
<br></blockquote><div><br>Yes, thank you.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks!<br>
<span class="HOEnZb"><font color="#888888">- Richard<br>
<br></font></span></blockquote><div><br>Thanks!<br>-- Matthieu <br></div></div>