[Bug c++/91705] New: operator++ broken in constexpr floating point code
john at johnmaddock dot co.uk
gcc-bugzilla@gcc.gnu.org
Mon Sep 9 07:12:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91705
Bug ID: 91705
Summary: operator++ broken in constexpr floating point code
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: john at johnmaddock dot co.uk
Target Milestone: ---
The following short program was accepted by gcc-8, but results in an error with
gcc-9.1:
template <class T>
constexpr T test_increment(T t)
{
return ++t;
}
int main()
{
constexpr double t = test_increment(2.0f);
static_assert(t == 3);
}
With:
/home/john/t.cpp: In function ‘int main()’:
/home/john/t.cpp:15:38: in ‘constexpr’ expansion of
‘test_increment<float>(2.0e+0f)’
/home/john/t.cpp:15:43: error: ‘((float)1 + 2.0e+0f)’ is not a constant
expression
15 | constexpr double t = test_increment(2.0f);
| ^
/home/john/t.cpp:16:19: error: non-constant condition for static assertion
16 | static_assert(t == 3);
The problem is present for all floating point types (float, double, long double
and __float128), but not integers. Replacing ++t with t+1 fixes the problem.
More information about the Gcc-bugs
mailing list