[Bug c++/76577] New: Tree folding may remove UB which causes invalid constexpr function calls to be accepted

ppalka at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Aug 14 16:51:00 GMT 2016


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

            Bug ID: 76577
           Summary: Tree folding may remove UB which causes invalid
                    constexpr function calls to be accepted
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

Test case:

constexpr int
foo (int a)
{
  return ((1 << a) & 1) == 0;
}

constexpr int bar = foo (-5);


g++ accepts this program even though the call to foo(-5) invokes UB (left shift
by a negative shift count) because the "((1 << a) & 1) == 0" gets folded by
match.pd to "a != 0" and the constexpr machinery evaluates this folded function
body instead of the original function body that contains the left shift.


More information about the Gcc-bugs mailing list