http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47570
Summary: "one() >= 0" isn't constexpr for unsigned int, yet == and > is. Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: yacw...@gmail.com Target: x86_64-unknown-linux-gnu Created attachment 23194 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23194 cxp_geq_uint.cpp I reduced the code down as far as I could. It's fairly self-explanatory. cxp_geq_uint.cpp ============================ unsigned int constexpr one() { return 1; } int constexpr one_B() { return 1; } int main() { // FAIL TO COMPILE: //static bool constexpr SC_huh = ((unsigned int)one()) >= ((unsigned int)0); //static bool constexpr SC_huh = one() >= ((unsigned int)0); static bool constexpr SC_huh = one() >= 0; // COMPILE OK: //static bool constexpr SC_huh = ((one() == 0) || (one() > 0)); //static bool constexpr SC_huh = one() == 0; //static bool constexpr SC_huh = one() > 0; //static bool constexpr SC_huh = one_B() >= 0; //static bool constexpr SC_huh = one() >= 1; return SC_huh; } ============================== g++ cxp_geq_uint.cpp --std=c++0x ============================== cxp_geq_uint.cpp: In function βint main()β: cxp_geq_uint.cpp:12:43: error: β(1u, true)β is not a constant expression ============================== I can see no reason why >= shouldn't be constexpr in this case. IIRC standard operators and literal casts always have defined behaviour for standard unsigned integers. As shown in the code, the problem goes away if: - The value to the right of >= is greater than 0. - The type is changed to (regular) int. - The operation is changed to == or > (or combining these manually to form >=) SPECS: gcc: version 4.6.0 2010-12-30 (experimental) (svn = 168358) - manually patched by (http://gcc.gnu.org/ml/gcc-patches/2007-04/msg00620.html) - patch shouldn't have any effect here. ubuntu: 10.10 (64 bit) intel: core2 duo I searched the buglist for constexpr & unsigned, didn't see any dupes myself. I guess this one probably won't be too hard to debug. I might even have a go if I get some spare time. HTH. Simon.