public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jyasskin at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-52119-4@http.gcc.gnu.org/bugzilla/> (raw) 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<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.
next reply other threads:[~2012-02-04 1:16 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-02-04 1:16 jyasskin at gcc dot gnu.org [this message] 2012-02-04 2:13 ` [Bug libstdc++/52119] " richard-gccbugzilla at metafoo dot co.uk 2012-02-04 9:59 ` paolo.carlini at oracle dot com 2012-02-04 10:04 ` paolo.carlini at oracle dot com 2012-02-05 2:05 ` jyasskin at gcc dot gnu.org 2012-02-05 12:59 ` paolo at gcc dot gnu.org 2012-02-05 13:01 ` [Bug c++/52119] " paolo.carlini at oracle dot com 2012-02-13 20:22 ` jason at gcc dot gnu.org 2012-02-13 22:18 ` richard-gccbugzilla at metafoo dot co.uk 2012-02-14 0:39 ` [Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed jason at gcc dot gnu.org 2013-06-05 17:26 ` jason at gcc dot gnu.org 2013-06-05 17:41 ` jason at gcc dot gnu.org 2013-06-05 22:37 ` jyasskin at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-52119-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).