https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63265
Bug ID: 63265
Summary: Constexpr variables can trigger spurious compiler
warnings
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: oneill+gccbugs at cs dot hmc.edu
This code defines two constexpr values that are equivalent. But one of them
produces a spurious warning
template <int lshift>
struct DoesntWarn {
static constexpr unsigned int v = lshift < 32 ? 1U << lshift : 0;
};
static_assert(DoesntWarn<32>::v == 0, "Impossible occurred");
template <int lshift>
struct SpuriouslyWarns {
static constexpr bool okay = lshift < 32;
static constexpr unsigned int v = okay ? 1U << lshift : 0;
};
static_assert(SpuriouslyWarns<32>::v == 0, "Impossible occurred");
Compiling with 4.9.1, we get
spurious.cpp: In instantiation of ‘constexpr const unsigned int
SpuriouslyWarns<32>::v’:
spurious.cpp:14:36: required from here
spurious.cpp:11:49: warning: left shift count >= width of type
static constexpr unsigned int v = okay ? 1U << lshift : 0;
^