public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48003] New: Regression in Template Constants from 4.5.2
@ 2011-03-06 12:07 swestrup at gmail dot com
  2011-03-06 12:29 ` [Bug c++/48003] " sefi@s-e-f-i.de
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: swestrup at gmail dot com @ 2011-03-06 12:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

           Summary: Regression in Template Constants from 4.5.2
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: swestrup@gmail.com


The following code compiles cleanly under g++ 4.5.2, but fails to compile under
g++ 4.6.0:

#include <climits>
#include <boost/mpl/int.hpp>
boost::mpl::int_<INT_MIN> foo;

It produces the errors:

/usr/local/include/boost/mpl/aux_/integral_wrapper.hpp: In
instantiation of ‘mpl_::int_<-0x00000000080000000>’:
test_test.cpp:8:27:   instantiated from here
/usr/local/include/boost/mpl/aux_/integral_wrapper.hpp:73:96: error:
‘2147483647’ is not a valid template argument for type ‘int’ because
it is a non-constant expression
/usr/local/include/boost/mpl/aux_/integral_wrapper.hpp:73:96: error:
overflow in constant expression [-fpermissive]

I tested this using Boost 1.46 on a Debian AMD_64 SID system running with a
2.6.36 kernel.


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

* [Bug c++/48003] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
@ 2011-03-06 12:29 ` sefi@s-e-f-i.de
  2011-03-06 14:06 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: sefi@s-e-f-i.de @ 2011-03-06 12:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

Philipp <sefi@s-e-f-i.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sefi@s-e-f-i.de

--- Comment #1 from Philipp <sefi@s-e-f-i.de> 2011-03-06 12:29:29 UTC ---
Small testcase.

#include <climits>

template<int N>
struct test
{
        typedef test<N - 1> prior;
};

typedef test<INT_MIN> foo;

foo f;

int main()
{
}


Of course INT_MIN - 1 is undefined but should gcc really evaluate it here?


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

* [Bug c++/48003] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
  2011-03-06 12:29 ` [Bug c++/48003] " sefi@s-e-f-i.de
@ 2011-03-06 14:06 ` paolo.carlini at oracle dot com
  2011-03-06 14:21 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-03-06 14:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-03-06 14:05:42 UTC ---
Apparently what used to be a warning not is an hard error.

Let's ask Jason, can be a regression.


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

* [Bug c++/48003] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
  2011-03-06 12:29 ` [Bug c++/48003] " sefi@s-e-f-i.de
  2011-03-06 14:06 ` paolo.carlini at oracle dot com
@ 2011-03-06 14:21 ` redi at gcc dot gnu.org
  2011-03-07 10:30 ` [Bug c++/48003] [4.6 Regression] " rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-03-06 14:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-06 14:21:12 UTC ---
EDG rejects it, clang doesn't


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

* [Bug c++/48003] [4.6 Regression] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
                   ` (2 preceding siblings ...)
  2011-03-06 14:21 ` redi at gcc dot gnu.org
@ 2011-03-07 10:30 ` rguenth at gcc dot gnu.org
  2011-03-07 10:42 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-07 10:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.03.07 10:30:34
   Target Milestone|---                         |4.6.0
            Summary|Regression in Template      |[4.6 Regression] Regression
                   |Constants from 4.5.2        |in Template Constants from
                   |                            |4.5.2
     Ever Confirmed|0                           |1

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-07 10:30:34 UTC ---
At least the error is confusing:

/usr/local/include/boost/mpl/aux_/integral_wrapper.hpp:73:96: error:
‘2147483647’ is not a valid template argument for type ‘int’ because
it is a non-constant expression

as ‘2147483647’ clearly looks like a constant expression ;)  It probably
should say '-2147483648 - 1' is not a constant expression - not sure
how difficult that would be.

-fpermissive doesn't make us accept the code.

Testcase w/o include:

template<int N>
struct test
{
          typedef test<N - 1> prior;
};

typedef test<-2147483647-1> foo;

foo f;

int main()
{
}


4.5 issues

t.C: In instantiation of 'test<-0x00000000080000000>':
t.C:9:5:   instantiated from here
t.C:4:31: warning: integer overflow in expression

that makes more sense.  We probably can go back to this behavior with
-fpermissive if accepting TREE_OVERFLOW consts as constant expressions.


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

* [Bug c++/48003] [4.6 Regression] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
                   ` (3 preceding siblings ...)
  2011-03-07 10:30 ` [Bug c++/48003] [4.6 Regression] " rguenth at gcc dot gnu.org
@ 2011-03-07 10:42 ` rguenth at gcc dot gnu.org
  2011-03-07 13:42 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-07 10:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-07 10:42:11 UTC ---
It would be nice to restore the old behavior of accepting the code with
at least -fpermissive.  Still needs investigation on whether this is
a rejects-valid bug or not - but it's really a corner-case, so will be
downgraded to P2 if no other P1 prevails.

Just to make you look at this bug as well.


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

* [Bug c++/48003] [4.6 Regression] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
                   ` (4 preceding siblings ...)
  2011-03-07 10:42 ` rguenth at gcc dot gnu.org
@ 2011-03-07 13:42 ` redi at gcc dot gnu.org
  2011-03-07 14:11 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-03-07 13:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-07 13:42:37 UTC ---
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#699 added integer
overflow ("a result that is not mathematically defined or not in the range of
representable values for its type") to the list of things that cause an
expression to not be a constant expression

The non-type template argument needs to be an integral constant-expression, but
it's not a constant expression due to the overflow, so the code is invalid.

Whether it should be accepted with -fpermissive is a separate matter, as is the
quality of diagnostic.


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

* [Bug c++/48003] [4.6 Regression] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
                   ` (5 preceding siblings ...)
  2011-03-07 13:42 ` redi at gcc dot gnu.org
@ 2011-03-07 14:11 ` rguenth at gcc dot gnu.org
  2011-03-08  5:28 ` jason at gcc dot gnu.org
  2011-03-08  7:31 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-07 14:11 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--- Comment #7 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-07 14:10:21 UTC ---
Ok.  Downgrading to P2 for the nice-to-have -fpermissive accepting the code.


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

* [Bug c++/48003] [4.6 Regression] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
                   ` (6 preceding siblings ...)
  2011-03-07 14:11 ` rguenth at gcc dot gnu.org
@ 2011-03-08  5:28 ` jason at gcc dot gnu.org
  2011-03-08  7:31 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-08  5:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-08 05:28:16 UTC ---
Author: jason
Date: Tue Mar  8 05:28:13 2011
New Revision: 170771

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170771
Log:
    PR c++/48003
    * pt.c (convert_nontype_argument): Fix -fpermissive allowing
    integer overflow.
    * semantics.c (potential_constant_expression_1): Check TREE_OVERFLOW.

Added:
    trunk/gcc/testsuite/g++.dg/template/nontype20.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/init/member1.C
    trunk/gcc/testsuite/g++.dg/parse/constant4.C
    trunk/gcc/testsuite/g++.dg/template/qualified-id3.C
    trunk/gcc/testsuite/g++.old-deja/g++.pt/crash10.C
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc


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

* [Bug c++/48003] [4.6 Regression] Regression in Template Constants from 4.5.2
  2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
                   ` (7 preceding siblings ...)
  2011-03-08  5:28 ` jason at gcc dot gnu.org
@ 2011-03-08  7:31 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-03-08  7:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48003

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|                            |FIXED

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-03-08 07:30:53 UTC ---
Fixed.


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

end of thread, other threads:[~2011-03-08  7:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-06 12:07 [Bug c++/48003] New: Regression in Template Constants from 4.5.2 swestrup at gmail dot com
2011-03-06 12:29 ` [Bug c++/48003] " sefi@s-e-f-i.de
2011-03-06 14:06 ` paolo.carlini at oracle dot com
2011-03-06 14:21 ` redi at gcc dot gnu.org
2011-03-07 10:30 ` [Bug c++/48003] [4.6 Regression] " rguenth at gcc dot gnu.org
2011-03-07 10:42 ` rguenth at gcc dot gnu.org
2011-03-07 13:42 ` redi at gcc dot gnu.org
2011-03-07 14:11 ` rguenth at gcc dot gnu.org
2011-03-08  5:28 ` jason at gcc dot gnu.org
2011-03-08  7:31 ` jakub 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).