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.
Hmm, this works for me on 3.4.2, can you try not with a OpenPKG package?
I can't reproduce this with 3.4.3 20041015 (prerelease) either. It must be a local patch in OpenPKG then. W.
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.
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.
Confirmed indeed. Sorry for my initial oversight... W.
And mine too. : Search converges between 2003-07-05-trunk (#285) and 2003-07-06-trunk (#286).
Subject: Bug 18020 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2004-10-27 02:23:16 Modified files: gcc/testsuite : ChangeLog gcc/cp : ChangeLog decl.c name-lookup.c parser.c pt.c search.c typeck.c Added files: gcc/testsuite/g++.dg/lookup: ns2.C gcc/testsuite/g++.dg/template: enum4.C expr1.C Log message: PR c++/18093 * search.c (current_scope): Return the innermost non-block scope, not the innermost non-block, non-namespace scope. (at_namespace_scope_p): Adjust accordingly. (dfs_accessible_post): Do not pass namespaces to is_friend. (dfs_walk_once_accessible_r): Likewise. * decl.c (grokvardecl): Adjust call to current_scope. (build_enumerator): Likewise. * parser.c (cp_parser_using_declaration): Likewise. (cp_parser_direct_declarator): Use at_namespace_scope_p instead of current_scope. (cp_parser_class_head): Adjust call to current_scope. * name-lookup.c (do_namespace_alias): Set the DECL_CONTEXT for the alias. PR c++/18020 * pt.c (tusbst_copy_and_build): Resolve enumeration constants to their underlying values. PR c++/18161 * typeck.c (build_binary_op): Honor build_type, even when in a template. PR c++/18093 * g++.dg/lookup/ns2.C: New test. PR c++/18020 * g++.dg/template/enum4.C: New test. PR c++/18161 * g++.dg/template/expr1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4501&r2=1.4502 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4454&r2=1.4455 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1318&r2=1.1319 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.87&r2=1.88 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.270&r2=1.271 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.937&r2=1.938 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.335&r2=1.336 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.588&r2=1.589 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/ns2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/expr1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Fixed in GCC 3.4.3.
Subject: Bug 18020 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: mmitchel@gcc.gnu.org 2004-10-27 04:32:57 Modified files: gcc/testsuite : ChangeLog gcc/cp : ChangeLog name-lookup.c pt.c Added files: gcc/testsuite/g++.dg/lookup: ns2.C gcc/testsuite/g++.dg/template: enum4.C Log message: PR c++/18093 * search.c (current_scope): Return the innermost non-block scope, not the innermost non-block, non-namespace scope. (at_namespace_scope_p): Adjust accordingly. (dfs_accessible_post): Do not pass namespaces to is_friend. (dfs_walk_once_accessible_r): Likewise. * decl.c (grokvardecl): Adjust call to current_scope. (build_enumerator): Likewise. * parser.c (cp_parser_using_declaration): Likewise. (cp_parser_direct_declarator): Use at_namespace_scope_p instead of current_scope. (cp_parser_class_head): Adjust call to current_scope. * name-lookup.c (do_namespace_alias): Set the DECL_CONTEXT for the alias. PR c++/18020 * pt.c (tusbst_copy_and_build): Resolve enumeration constants to their underlying values. PR c++/18093 * g++.dg/lookup/ns2.C: New test. PR c++/18020 * g++.dg/template/enum4.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.297&r2=1.3389.2.298 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/ns2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.171&r2=1.3892.2.172 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.34.2.18&r2=1.34.2.19 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.816.2.43&r2=1.816.2.44