[PATCH] Warning on unevaluated expression contexts with side effects

Aaron Ballman aaron at aaronballman.com
Tue Nov 25 06:51:41 PST 2014


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 --------------
A non-text attachment was scrubbed...
Name: UnevaluatedExpr.patch
Type: application/octet-stream
Size: 16607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141125/e0d33839/attachment.obj>


More information about the cfe-commits mailing list