User account creation filtered due to spam.

Bug 15877 - [3.4/4.0 Regression] valid code using templates and anonymous enums is rejected
Summary: [3.4/4.0 Regression] valid code using templates and anonymous enums is rejected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 3.4.1
Assignee: Mark Mitchell
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2004-06-08 18:14 UTC by Andrew Pinski
Modified: 2005-05-02 08:04 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.4.0 4.0.0
Last reconfirmed: 2004-06-08 19:14:56


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2004-06-08 18:14:44 UTC
Instead of keeping PR 15554 open, I decided to open a new bug as it is caused by a different problem.

template <int n> struct T1 { enum { N = 3 }; };
template <int n> struct T2 { enum { N = n, N1 = T1<N>::N }; };
Comment 1 Wolfgang Bangerth 2004-06-08 19:14:55 UTC
Yes, this was already confirmed. It's a critical regression. 
W. 
Comment 2 Mark Mitchell 2004-06-09 18:42:22 UTC
Working on a fix.
Comment 3 CVS Commits 2004-06-10 14:26:32 UTC
Subject: Bug 15877

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-06-10 14:26:23

Modified files:
	gcc/cp         : ChangeLog parser.c pt.c typeck.c 
Added files:
	gcc/testsuite/g++.dg/conversion: const1.C reinterpret1.C 
	gcc/testsuite/g++.dg/template: enum2.C error13.C 

Log message:
	PR c++/15227
	* parser.c (cp_parser_direct_declarator): Robustify.
	
	PR c++/15877
	* pt.c (tsubst_copy): Use decl_constant_value on enumeration
	constants in non-dependent contexts.
	
	PR c++/14211
	PR c++/15076
	* typeck.c (build_static_cast): Wrap casts in NON_LVALUE_EXPR when
	necessary.
	
	PR c++/14211
	* g++.dg/conversion/const1.C: New test.
	
	PR c++/15076
	* g++.dg/conversion/reinterpret1.C: New test.
	
	PR c++/15877
	* g++.dg/template/enum2.C: New test.
	
	PR c++/15227
	* g++.dg/template/error13.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4089&r2=1.4090
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.202&r2=1.203
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.860&r2=1.861
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.548&r2=1.549
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/conversion/const1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/conversion/reinterpret1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/error13.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 CVS Commits 2004-06-10 14:27:00 UTC
Subject: Bug 15877

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-06-10 14:26:50

Modified files:
	gcc/cp         : ChangeLog parser.c pt.c typeck.c 
Added files:
	gcc/testsuite/g++.dg/conversion: const1.C reinterpret1.C 
	gcc/testsuite/g++.dg/template: enum2.C error13.C 

Log message:
	PR c++/15227
	* parser.c (cp_parser_direct_declarator): Robustify.
	
	PR c++/15877
	* pt.c (tsubst_copy): Use decl_constant_value on enumeration
	constants in non-dependent contexts.
	
	PR c++/14211
	PR c++/15076
	* typeck.c (build_static_cast): Wrap casts in NON_LVALUE_EXPR when
	necessary.
	
	PR c++/14211
	* g++.dg/conversion/const1.C: New test.
	
	PR c++/15076
	* g++.dg/conversion/reinterpret1.C: New test.
	
	PR c++/15877
	* g++.dg/template/enum2.C: New test.
	
	PR c++/15227
	* g++.dg/template/error13.C: New test.

Patches:
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.119&r2=1.3892.2.120
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.157.2.32&r2=1.157.2.33
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.29&r2=1.816.2.30
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.19&r2=1.519.2.20
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/conversion/const1.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/conversion/reinterpret1.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/enum2.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/error13.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 5 Mark Mitchell 2004-06-10 14:29:48 UTC
Fixed in GCC 3.4.1.
Comment 6 Mark Mitchell 2004-06-10 14:31:40 UTC
Fixed in GCC 3.4.1.
Comment 7 Bill Clarke 2005-05-02 05:46:04 UTC
the following code is fairly similar to this bug, but it is rejected by g++ 4.0.0:
x.cc:10: error: '(Arg1 + 1)' is not a valid template argument for type 'int'
because it is a non-constant expression
x.cc:10: error: 'value' is not a member of '<declaration error>'

is it a new bug?  (accepted by comeau c++)

(NoBug1 and NoBug2 are workarounds)

"""
template <int x> struct Id {
  enum { value = x };
};

template <int Arg1>
struct Bug {
  enum Spam {
    enum1 = Arg1,
    enum2 = enum1+1,
    enum3 = Id<enum2>::value
  };
};

template <int Arg1>
struct NoBug1 {
  enum {
    enum1 = Arg1,
    enum2 = Arg1+1,
    enum3 = Id<enum2>::value
  };
};

template <int Arg1>
struct NoBug2 {
  enum {
    enum1 = Arg1,
    enum2 = enum1+1
  };
  enum {
    enum3 = Id<enum2>::value
  };
};
"""
Comment 8 Giovanni Bajo 2005-05-02 08:04:02 UTC
Please open a new bugreport for this bug.