<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 31, 2015 at 1:01 PM, Richard <span dir="ltr"><<a href="mailto:legalize@xmission.com" target="_blank">legalize@xmission.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
In article <<a href="mailto:CAENS6EuerX1Fvf0NEo7fYvn3pR1RJHQxahGA%2B-C8ztZkgRi5yQ@mail.gmail.com">CAENS6EuerX1Fvf0NEo7fYvn3pR1RJHQxahGA+-C8ztZkgRi5yQ@mail.gmail.com</a>>,<br>
<span class=""> David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> writes:<br>
<br>
> On Tue, Mar 31, 2015 at 10:06 AM, Richard <<a href="mailto:legalize@xmission.com">legalize@xmission.com</a>> wrote:<br>
</span><span class="">> > In the case of a return statement, you don't need to do anything.<br>
> ><br>
> > If they wrote 'if (sp != nullptr) return true; else return false;',<br>
> > then the tool would replace this with 'return sp != nullptr;'.<br>
> ><br>
> > If they wrote 'if (sp) return true; else return false;', the tool<br>
> > would replace this with 'return sp;'.<br>
> ><br>
><br>
> This ^ transformation is most likely not valid for any modern user defined<br>
> type (because they'll have an explicit operator bool, not an implicit one):<br>
><br>
> $ cat sp.cpp<br>
> #include <memory><br>
><br>
> bool f1(std::unique_ptr<int> u) {<br>
> if (u)<br>
> return true;<br>
> return false;<br>
> }<br>
><br>
> bool f2(std::unique_ptr<int> u) {<br>
> return u;<br>
> }<br>
> $ clang++-tot sp.cpp -fsyntax-only -std=c++11<br>
> sp.cpp:10:10: error: no viable conversion from 'std::unique_ptr<int>' to<br>
> 'bool'<br>
> return u;<br>
> ^<br>
> 1 error generated.<br>
<br>
</span>Good point. So I guess I need to handle these cases and it looks like<br>
I can't avoid some type introspection in order to figure out what to<br>
do.<br>
<span class=""><br>
> > At this point I am only concerned about correctness.<br>
><br>
> Sure, but your transformation is stylistic in nature - so it's not just<br>
> important to preserve semantics, but also to improve readability. Perhaps<br>
> it's worth not offering a fixit hint in these cases, until good quality<br>
> ones can be provided? I'm not sure.<br>
<br>
</span>I think some type introspection can be done to deal with builtin types<br>
and standard library types.<br>
<br>
Yes, the transformation is stylistic, but it is also human invoked.<br></blockquote><div><br>clang-tidy isn't necessarily used for transformation in particular - I think of it more as a linter tool: suggesting problems, sometimes being able to provide likely solutions. So I wouldn't necessarily worry about providing fixit hints in all cases, especially as the fixit gets harder to provide with high quality, etc.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The user has asked for this transformation to be performed, so I'm ok<br>
with transforming it in such a way that it leaves correctness intact<br>
albeit possibly with an ugly static_cast<> lurking in there if I can't<br>
figure out something better. </blockquote><div><br>I don't fundamentally object to a fixit hint including static_cast<bool>() or bool(), I'm just not sure it's necessarily better than not suggesting one & leaving it up to the user in cases where it's not obvious *shrug*<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> (Personally I don't know why people are<br>
against the 'functional cast' bool(e), particularly when that's the<br>
wording in the standard.)<br></blockquote><div><br>I tend to treat c-style casts with more care because I know they can do more problematic transformations (I suppose when the target type is bool this isn't an issue? I'm not sure - I'd have to go back & read the spec about the sequence of conversions c-style casts can perform)<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">--<br>
"The Direct3D Graphics Pipeline" free book <<a href="http://tinyurl.com/d3d-pipeline" target="_blank">http://tinyurl.com/d3d-pipeline</a>><br>
The Computer Graphics Museum <<a href="http://ComputerGraphicsMuseum.org" target="_blank">http://ComputerGraphicsMuseum.org</a>><br>
The Terminals Wiki <<a href="http://terminals.classiccmp.org" target="_blank">http://terminals.classiccmp.org</a>><br>
Legalize Adulthood! (my blog) <<a href="http://LegalizeAdulthood.wordpress.com" target="_blank">http://LegalizeAdulthood.wordpress.com</a>><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div></div>