<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 26, 2014 at 4:18 PM, Eugene Toder <span dir="ltr"><<a href="mailto:eltoder@gmail.com" target="_blank">eltoder@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>I find clang's unused variable warning very useful to keep the code from accumulating garbage over time. For built-in types it works great, but I've noticed that for user-defined types it often misses unused variables. The current logic for user-defined types is to warn on unused variable if 1) the type has a trivial destructor 2) the constructor is either elided or trivial, or the type is marked with warn_unused attribute [1].</div>
<div>Does anyone object to extending 2) to allow constexpr constructors? The reasoning is that constexpr constructors are not supposed to have any side-effects.</div></div></blockquote><div><br></div><div>Not quite true, unfortunately - a constexpr function (or constructor) /can/ be used in constexpr contexts but only has to have no side effects for the /particular/ codepaths that are called from constexpr contexts.<br>
<br>eg:<br><br>constexpr int func(bool b) { if (b) printf("stuff") return 3; }<br><br>constexpr int x = func(false);<br>const int y = func(true);<br><br>is valid code, as I understand it. But we might be able to check the particular caller, to see if it's constexpr - but that could have performance implications.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>What about a check that constructor does not have side-effects, even if it's not marked as constexpr? This can start by using the same code as the one for constexpr checking. Is this the right thing in the compiler, or should this go into clang-tidy?<br>
</div></div></blockquote><div><br></div><div>Might be a bit too much to do.<br><br>The aggresive way to do this would be to assume all types are "Value" types and warn on all unused variables. Then add an attribute to annotate types that have side effects (and even specifically types with scoped side effects - such as MutexLock, so you could warn on "MutexLock(n);" but not warn on "MutexLock(n), func();")</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>
</div><div><br></div><div>[1] <a href="http://clang.llvm.org/doxygen/SemaDecl_8cpp_source.html#l01426" target="_blank">http://clang.llvm.org/doxygen/SemaDecl_8cpp_source.html#l01426</a><br></div><div><br></div><div>Thanks,</div>
<div>Eugene</div>
</div>
<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>
<br></blockquote></div><br></div></div>