[PATCH] Warning on unevaluated expression contexts with side effects
Richard Trieu
rtrieu at google.com
Tue Nov 25 18:59:03 PST 2014
After running some code through a Clang with this patch, a few issues came
up:
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.
2) This warning is counting a dereference of a volatile pointer as a side
effect, for instance:
int* volatile x;
return sizeof(*x);
3) This hits an llvm_unreachable:
template <typename T> void F(T t) {}
template <typename T> void G(T t) { decltype(&F<T>) x; }
template <typename T> class V {};
void foo() { G(V<int>()); }
shouldn't see dependent / unresolved nodes here
UNREACHABLE executed at ../tools/clang/lib/AST/Expr.cpp:2891!
On Tue, Nov 25, 2014 at 6:51 AM, Aaron Ballman <aaron at aaronballman.com>
wrote:
> The attached patch adds a -Wunused-value warning when an expression
> with side effects is used in an unevaluated expression context, such
> as sizeof(), or decltype(). It mostly reuses the logic from
> Expr::HasSideEffects, except with a flag that treats certain
> expressions as not having side effects -- mostly
> instantiation-dependent contexts, and function call-like operations.
>
> int f();
> int j = 0;
>
> (void)sizeof(f()); // Ok
> (void)sizeof(++j); // Warn
> (void)sizeof(int[++j]); // Ok
>
> I've added support for: sizeof, typeid, _Generic, _Alignof, noexcept,
> and decltype.
>
> ~Aaron
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141125/cd4aad59/attachment.html>
More information about the cfe-commits
mailing list