https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93491
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Const functions by definition dont trap or throw. So adding const to a function that traps makes the testcase undefined. Do you have a testcase were gcc does this optimize without the user adding const and still traps?