c++/7181: foo<n>::bar = foo<n-1>::bar + foo<n-2>::bar evaluates to zero at compile time

Mark Mitchell mark@codesourcery.com
Tue Jul 2 13:31:00 GMT 2002



--On Tuesday, July 02, 2002 08:42:23 PM +0100 Nathan Sidwell 
<nathan@codesourcery.com> wrote:

> mmitchel@gcc.gnu.org wrote:
>>
>> Synopsis: foo<n>::bar = foo<n-1>::bar + foo<n-2>::bar evaluates to zero
>> at compile time
>>
>> State-Changed-From-To: analyzed->closed
>> State-Changed-By: mmitchel
>> State-Changed-When: Tue Jul  2 11:31:51 2002
>> State-Changed-Why:
>>     This code does not have well-defined behavior.
> How have you come to this conclusion? The last sentance of
> [14.7.1]/1 indicates that we must instantiate the definition of
> Foo<N>::value. I see nothing in [3.6.2] or [3.8] which disallows it.
>
> Or are you saying this is a case of [14.7.3]/7?\

The standard doesn't specifies that the point of instantiation for the
various static data members is "the same".  It doesn't say which one
gets instantiated first.  Nor, according to John, does it say which one
gets initialized first.

So, I think the standard says "all those things get instantiated and
initialized in some order" -- but not which order, similar to the
example in 3.6.2.

These are dynamic initializations; the initializers are not constant
expressions.

-- 
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com



More information about the Gcc-bugs mailing list