https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119936
Bug ID: 119936 Summary: add warning if assume expression is compile-time evaluated to false Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: drepper.fsp+rhbz at gmail dot com Target Milestone: --- I incorrectly used the assume attribute like this (simplified): template<bool eq> int f(int v) { [[assume(eq && v < 10)]]; return v + 1; } template int f<false>(int); template int f<true>(int); The function was larger and unlike in this case, there was actually code being generated for it (here, code is only created for the second instantiation). In my case the generated code was nonsense and lead to hard-to-find crashes. Correctly the attribute should have been something like [[assume(!eq || v<10)]]; The C++ standard requires that the assume expression can be evaluated to 'true' in some cases. Otherwise, I guess, the behavior is undefined. Therefore I think the compiler should issue a warning in case the expression is always evaluating to false and the compiler acts on this.