Thanks for the reply, but the solution was right there all along... if (volatile bool _ = false) On Mon, Jul 24, 2023 at 12:53 AM David Brown <david.brown@xxxxxxxxxxxx> wrote: > On 23/07/2023 16:27, Julian Waters via Gcc-help wrote: > > I just tried it and it does work, even on O3, however I would like to > avoid > > allocating a variable if possible. It's a shame that gnu::used doesn't > > seem to work with if statements (If anyone knows where to look in the > > source code do tell me). But thanks for the suggestion nonetheless! > > > > How about: > > static inline bool False(void) { > bool b = false; > asm volatile("" : "+r" (b)); > return b; > } > > Then use "if (False()) ..." instead of "if (false) ...". > > The generated overhead is going to be minimal, and no volatile variables > are created. It's also quite cool (IMHO) to have 100% portable inline > assembly! > > mvh., > > David > > > > > best regards, > > Julian > > > > On Sun, Jul 23, 2023 at 10:14 PM Gabriel Ravier <gabravier@xxxxxxxxx> > wrote: > > > >> On 7/23/23 14:45, Julian Waters via Gcc-help wrote: > >>> Hi all, > >>> > >>> Is there a way to stop gcc from nuking an if (false) statement and the > >>> corresponding branch from the compiled code for debugging purposes? > >>> Even turning off all optimizations doesn't achieve this > >>> > >>> best regards, > >>> Julian > >> > >> IMO the simplest way would be to define something like `static const > >> volatile bool unoptimizable_false = false;` somewhere and use it in > >> place of `false`, when you want to avoid the if statement being > >> optimized out. > >> > >> > > > >