#include <iostream> using namespace std; Here is a very dangerous situation that compiler can catch illustrated by the following example: when sizeof has non-lvalue argument. --- example --- int f() { cout << "I am f" << endl; return 5; } int main() { cout << "sizeof=" << sizeof(f()) << endl; // HERE THE WARNING SHOULD BE ISSUED return (0); }
Well when VLA's get added, sometimes sizeof will have side effects. An example: sizeof(int[n++])
Warning should be issued in this case as well. Since this isn't an expected behavior to ignore "n++".
Confirmed. Using sizeof with an argument that appears to have side effects but isn't evaluated seems like an error waiting to happen. W.
It might makes sense to provide the functionality under the -Wunevaluated-expression option for compatibility with clang: $ cat u.c && clang -Wall -c u.c int foo (int i) { int a [i]; return sizeof (a [i++]); } u.c:4:19: warning: expression with side effects has no effect in an unevaluated context [-Wunevaluated-expression] return sizeof (a [i++]); ^ 1 warning generated.