https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78948
Bug ID: 78948
Summary: constexpr if instantiating too eagerly
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rogero at howzatt dot demon.co.uk
Target Milestone: ---
The following code fails to compile:
---- CODE ----
template <int T>
void sizeof_mismatch()
{
static_assert(T == 0, "sizeof mismatch");
}
int main()
{
if constexpr(sizeof(long long) == sizeof(char*))
;
else
sizeof_mismatch<sizeof(long long)>();
}
---- ENDS ----
gcc head 2016-12-19
prog.cc: In instantiation of 'void sizeof_mismatch() [with int T = 8]':
prog.cc:12:40: required from here
prog.cc:4:5: error: static assertion failed: sizeof mismatch
static_assert(T == 0, "sizeof mismatch");
^~~~~~~~~~~~~
However the instantiation of sizeof_mismatch is not required because it is not
odr-used (6.4.1p2 [stmt.if] it is a 'discarded statement')