https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89029
--- Comment #4 from Peter Dimov <pdimov at gmail dot com> --- (In reply to Jonathan Wakely from comment #3) > c.f. https://gcc.gnu.org/ml/libstdc++/2018-03/msg00031.html and the replies Yes, pretty much. > I doubt we would catch many bugs that way, as most bugs would involve > non-constant indices and vectors that have changed size dynamically at > run-time. It's still pretty cool when it works, f.ex. here: https://godbolt.org/z/fHCB16 Annoying that we're so close to useful static analysis but it doesn't _quite_ work. (Also note how the code for g() goes straight to assert without telling anyone.) >RESOLVED INVALID Too bad. FWIW, Clang trunk doesn't seem to suffer from the false positive problem. It also "proves" the assertion failure in g, but not in f: https://godbolt.org/z/92WyvR. (It also doesn't support __attribute((error)), which makes this technique limited in value.) Maybe the correct way to go about this is just to mark __assert_fail in some manner ("warn if unconditionally called"), instead of trying to (ab)use __builtin_constant_p.