<div dir="ltr">After running some code through a Clang with this patch, a few issues came up:<div><br></div><div>1) This warning should likely be disabled in macros.  Some macros will perform a sizeof on the macro argument which will trigger this warning even if argument is used elsewhere in the macro expansion.</div><div><br></div><div>2) This warning is counting a dereference of a volatile pointer as a side effect, for instance:</div><div><div>  int* volatile x;</div><div>  return sizeof(*x);</div></div><div><br></div><div>3) This hits an llvm_unreachable:</div><div><div><br></div><div>template <typename T> void F(T t) {}</div><div>template <typename T> void G(T t) { decltype(&F<T>) x; }<br></div><div>template <typename T> class V {};<br></div><div>void foo() { G(V<int>()); }<br></div></div><div><br></div><div><div>shouldn't see dependent / unresolved nodes here</div><div>UNREACHABLE executed at ../tools/clang/lib/AST/Expr.cpp:2891!</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 25, 2014 at 6:51 AM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The attached patch adds a -Wunused-value warning when an expression<br>
with side effects is used in an unevaluated expression context, such<br>
as sizeof(), or decltype(). It mostly reuses the logic from<br>
Expr::HasSideEffects, except with a flag that treats certain<br>
expressions as not having side effects -- mostly<br>
instantiation-dependent contexts, and function call-like operations.<br>
<br>
int f();<br>
int j = 0;<br>
<br>
(void)sizeof(f()); // Ok<br>
(void)sizeof(++j); // Warn<br>
(void)sizeof(int[++j]); // Ok<br>
<br>
I've added support for: sizeof, typeid, _Generic, _Alignof, noexcept,<br>
and decltype.<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span></blockquote></div><br></div>