------- Comment #6 from jobnoorman at gmail dot com 2010-08-17 10:49 ------- (In reply to comment #5) > For inline-asm? Certainly not. Consider much simpler: > void foo (void) > { > int i; > i = 6; > asm volatile ("" : : "i" (i)); > } > which will work with -O and above, but not for -O0, for exactly the same > reason.
IMHO, your example should always give an error. The "i" constraint is to be used for constant integer operands. A variable of type "int" just isn't constant, even if GCC is smart enough to optimize the variable away and use a constant instead. Your example will always work if you make "i" of type "const int". I also think there is an important difference between your example and mine: the expression "(plain_foobar_t)&Foo::foobar" is a constant expression (please correct me if I'm wrong) and thus should always be allowed when using the "i" constraint. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45303