From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24327 invoked by alias); 2 Jul 2002 20:56:17 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 24311 invoked by uid 71); 2 Jul 2002 20:56:13 -0000 Date: Tue, 02 Jul 2002 13:56:00 -0000 Message-ID: <20020702205613.24309.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Nickolai Dobrynin Subject: Re: c++/7181: foo::bar = foo::bar + foo::bar evaluates to zero at compile time Reply-To: Nickolai Dobrynin X-SW-Source: 2002-07/txt/msg00081.txt.bz2 List-Id: The following reply was made to PR c++/7181; it has been noted by GNATS. From: Nickolai Dobrynin To: Paolo Carlini Cc: , , , , Mark Mitchell , Nathan Sidwell Subject: Re: c++/7181: foo::bar = foo::bar + foo::bar evaluates to zero at compile time Date: Tue, 2 Jul 2002 15:52:27 -0500 (CDT) Hello! Actually, the original example from the "Generative Programming" book looked like this: #include using namespace std; template struct Fib { enum { RET = Fib::RET + Fib::RET }; }; template<> struct Fib<0> { enum { RET = 0 }; }; template<> struct Fib<1> { enum { RET = 1 }; }; void main() { cout << Fib<8>::RET << endl; } -- which, evidently, is not identical to what I was submitting in my original message. After eliminating the "enum hack" (an optional step), i.e. replacing enum with const static int, #include using namespace std; template struct Fib { const static int RET = Fib::RET + Fib::RET; }; struct Fib<0> { const static int RET = 0; }; struct Fib<1> { const static int RET = 1; }; int main() { cout << Fib<40>::RET << endl; return 0; } this will indeed produce a valid output. I just think of it as being totally counter intuitive that the same nifty feature is not valid (is NO LONGER valid, would be a better way to say it) on non-constant initializers. So, would indeed this be possible to restore the behavior of 2.95.x or it would come in conflict with something else? Any opinions on that? Regards, Nickolai PS Is it a normal behavior that the option -ftemplate-depth-... is no longer needed in order for the example above to compile properly? On Tue, 2 Jul 2002, Paolo Carlini wrote: > Hi, > > from a very practical point of view, would be difficult to restore the > behaviour of 2.95.x? Note that Intel and Comeau adopts that "particular" > initialization order and the current "equivalent" one ;-) breaks a whole > body of literature on template metaprogramming... > > Ciao, Paolo. > > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7181 > > >