It would be useful to implement a __builtin_warning function to delay a warning which may be removed later by dead code elimination. One application could be PR48655, where warnings are issued about temporary Fortran arrays which are eliminated by the middle end. See the discussion at https://gcc.gnu.org/ml/gcc/2019-04/msg00275.html . (Come to think of it, a __builtin_error function could also be useful in some contexts).
Error can be implement using the error attribute on a function.
As Jeff said this would be useful to avoid false positives in cases like bug 89337 comment #12.
I'm not sure a function call is the proper way to handle this. It would maybe be better to use a DEBUG-stmt like thing (maybe even actually a debug stmt!). In theory it would be possible to emit those into DWARF and trigger the warnings at runtime (under inspection of an appropriate tool like valgrind).
There is a prototype patch by Martin Sebor at https://gcc.gnu.org/pipermail/gcc-patches/2019-October/531812.html
This would be very useful for the C++ library where we currently have precondition checks that: - abort at runtime if you compile with -D_GLIBCXX_ASSERTIONS, or - fail at compile-time if they are constexpr **and** are actually evaluated during constexpr evaluation The runtime assertions are good, but not enabled by default, and an earlier warning at compile time means the problem can be found sooner. The constexpr errors are good, but don't apply to non-constexpr calls, even if all the arguments are known during compilation. It would be nice to be able to also issue warnings for non-constexpr calls, when compiled without -D_GLIBCXX_ASSERTIONS.