https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113565

--- Comment #4 from Jan Schultke <janschultke at googlemail dot com> ---
I would expect an error here because things that are undefined behavior are
generally supposed to fail in constant expressions. I don't see a good reason
why builtins should be exempt from that rule.

The lack of diagnostic has cost me a few minutes of debugging yesterday. I had
a static_assert:

> static_assert(my_function(0u) == 32);

This succeeded at compile time, but my_function(0) would return 0 at run-time
as a result of passing through to __builtin_clz. UBSan may have caught it, but
regardless, it's not sane to have different results inside/outside constant
expressions like that.
  • [Bug c++/113565] __builtin_... janschultke at googlemail dot com via Gcc-bugs

Reply via email to