18020 – [3.4/4.0 regression] rejects valid definition of enum value in template

Description Guillaume Morin 2004-10-15 18:05:09 UTC

Here we go:

gmorin@linux:~> cat foo.cpp
template <typename FOO>
struct bar {
    enum {
        MASK = ((1 << 17)-1)
        , IT_MASK = (~MASK)
        , ITERATION_INC = (MASK+1)
    };
};

int baz = bar<int>::IT_MASK;
gmorin@linux:~> g++ -o /dev/null -c foo.cpp
foo.cpp: In instantiation of `bar<int>':
foo.cpp:10:   instantiated from here
foo.cpp:3: error: enumerator value for `IT_MASK' not integer constant
gmorin@linux:~> gcc -v
Reading specs from /openpkg/lib/gcc/i686-pc-linux-gnu/3.4.2/specs
Configured with: ../configure --cache-file=./config.cache
--srcdir=/openpkg/RPM/TMP/gcc-3.4.2/obj/.. --prefix=/openpkg
--exec-prefix=/openpkg --includedir=/openpkg/include/gcc
--libexecdir=/openpkg/libexec/gcc --with-gxx-include-dir=/openpkg/include/g++
--with-local-prefix=/openpkg/lib/gcc --enable-languages=c,c++
--enable-threads=posix --disable-maintainer-mode --disable-shared --disable-nls
--with-gnu-ld --with-ld=/openpkg/bin/ld --with-gnu-as --with-as=/openpkg/bin/as
Thread model: posix
gcc version 3.4.2 (OpenPKG-CURRENT)
gmorin@linux:~> uname -a
Linux linux 2.4.21-99-smp4G #1 SMP Wed Sep 24 14:13:20 UTC 2003 i686 athlon i386
GNU/Linux

This is a Suse 9.0 with gcc from CURRENT OpenPKG. It works if you remove the
template declaration.

Comment 1 Andrew Pinski 2004-10-15 18:21:22 UTC

Hmm, this works for me on 3.4.2, can you try not with a OpenPKG package?

Comment 2 Wolfgang Bangerth 2004-10-15 18:57:15 UTC

I can't reproduce this with 3.4.3 20041015 (prerelease) either. It must 
be a local patch in OpenPKG then. 
 
W. 

Comment 3 Guillaume Morin 2004-10-15 19:07:17 UTC

Hi,

As far as I know, OpenPKG does not apply any patched on this gcc. Furthermore, I
have another gcc 3.4.2 built from the vanilla source on Solaris :

gmorin@sundev9:~$ /unix-SunOS-sparc-5.8-def/bin/g++ -o /dev/null -c foo.cpp
foo.cpp: In instantiation of `bar<int>':
foo.cpp:11:   instantiated from here
foo.cpp:3: error: enumerator value for `IT_MASK' not integer constant
gmorin@sundev9:~$ /unix-SunOS-sparc-5.8-def/bin/g++ -v                  
Reading specs from
/unix-SunOS-sparc-5.8-def/bin/../lib/gcc/sparc-sun-solaris2.8/3.4.2/specs
Configured with: ../gcc-3.4.2/configure --prefix=/unix-SunOS-sparc-5.8-def/
--enable-languages=c,c++
Thread model: posix
gcc version 3.4.2
gmorin@sundev9:~$ uname -a
SunOS sundev9 5.8 Generic_108528-19 sun4u sparc SUNW,Sun-Fire
gmorin@sundev9:~$

I strongly think this bug should be reopened. It looks extremely likely that it
is present in 3.4.2, and it is not sure yet it is fixed 3.4.3.

Thanks,

Guillaume.

Comment 4 Wolfgang Bangerth 2004-10-15 19:17:03 UTC

My fault: I missed the last line of the testcase where the instantiation 
is. With this line I can reproduce this bug with both stock 3.4.2 as well 
as with the present top-of-branch 3.4 compiler. 
 
The bug doesn't happen with gcc 3.3, which makes this a regression. Here's 
the testcase in slightly modified version: 
------------------ 
template <typename> struct bar { 
    enum { 
          e1 = 1, 
          e2 = ~e1 
    }; 
}; 
template struct bar<int>; 
-------------------- 
 
g/x> /home/bangerth/bin/gcc-4*/bin/c++ -c x.cc 
x.cc: In instantiation of `bar<int>': 
x.cc:7:   instantiated from here 
x.cc:2: error: enumerator value for 'e2' not integer constant 
 
The problem doesn't happen when the class isn't a template. 
W. 

Comment 5 Wolfgang Bangerth 2004-10-15 19:17:30 UTC

Confirmed indeed. Sorry for my initial oversight... 
W. 

Comment 6 Andrew Pinski 2004-10-15 19:43:33 UTC

And mine too.
: Search converges between 2003-07-05-trunk (#285) and 2003-07-06-trunk (#286).

Comment 8 Mark Mitchell 2004-10-27 04:33:04 UTC

Fixed in GCC 3.4.3.