public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/52119] New: numeric_limits::min() is not a constant expression
@ 2012-02-04  1:16 jyasskin at gcc dot gnu.org
  2012-02-04  2:13 ` [Bug libstdc++/52119] " richard-gccbugzilla at metafoo dot co.uk
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: jyasskin at gcc dot gnu.org @ 2012-02-04  1:16 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-06-05 22:37 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-04  1:16 [Bug libstdc++/52119] New: numeric_limits::min() is not a constant expression jyasskin at gcc dot gnu.org
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

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).