http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119
Bug #: 52119 Summary: numeric_limits::min() is not a constant expression Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: jyass...@gcc.gnu.org numeric_limits<T>::min() is defined as (__glibcxx_signed (T) ? (T)1 << __glibcxx_digits (T) : (T)0). Unfortunately, shifting into the sign bit is undefined behavior (C++11[expr.shift]p2), and undefined behavior makes an expression non-constant. clang as of (their) r149727 diagnoses this as: $ echo '#include <limits>' | clang++ -nostdinc++ -Igcc-4.7-svn/include/c++/4.7.0/{,x86_64-unknown-linux-gnu} -std=c++11 -Wsystem-headers -fsyntax-only -x c++ - gcc-4.7-svn/include/c++/4.7.0/limits:654:7: error: constexpr function never produces a constant expression min() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_min (wchar_t); } ^ gcc-4.7-svn/include/c++/4.7.0/limits:654:44: note: value 2147483648 is outside the range of representable values of type 'int' min() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_min (wchar_t); } ^ gcc-4.7-svn/include/c++/4.7.0/limits:131:32: note: expanded from macro '__glibcxx_min' (__glibcxx_signed (T) ? (T)1 << __glibcxx_digits (T) : (T)0) ^ gcc-4.7-svn/include/c++/4.7.0/limits:784:31: warning: shift count >= width of type [-Wshift-count-overflow] min() noexcept { return __glibcxx_min (char32_t); } ^~~~~~~~~~~~~~~~~~~~~~~~ A better definition might be -__glibcxx_max(T)-1. This bug is also in 4.6.2. 4.5.0 didn't declare min() as constexpr.