This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/76577] New: Tree folding may remove UB which causes invalid constexpr function calls to be accepted
- From: "ppalka at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 14 Aug 2016 16:51:20 +0000
- Subject: [Bug c++/76577] New: Tree folding may remove UB which causes invalid constexpr function calls to be accepted
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
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.