From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4921 invoked by alias); 4 Feb 2012 01:16:43 -0000 Received: (qmail 4912 invoked by uid 22791); 4 Feb 2012 01:16:43 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CX X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 04 Feb 2012 01:16:28 +0000 From: "jyasskin at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/52119] New: numeric_limits::min() is not a constant expression Date: Sat, 04 Feb 2012 01:16:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jyasskin at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-02/txt/msg00450.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: jyasskin@gcc.gnu.org numeric_limits::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 ' | 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.