[cfe-dev] Additional instantiations of anonymous enum inside a template

Richard Smith richard at metafoo.co.uk
Mon Oct 13 09:02:47 PDT 2014


On 13 Oct 2014 01:06, "Pavel Morozkin" <pavel.morozkin at gmail.com> wrote:
>
> On 13 October 2014 03:53, Richard Smith <richard at metafoo.co.uk> wrote:
>>
>> On Sun, Oct 12, 2014 at 3:29 AM, Pavel Morozkin <pavel.morozkin at gmail.com>
wrote:
>>>
>>> Hello cfe-dev group,
>>>
>>> Consider this template metaprogram:
>>> template <unsigned N> struct fib { enum { value = fib<N-1>::value +
fib<N-2>::value}; };
>>> template <> struct fib<1> { enum { value = 1 }; };
>>> template <> struct fib<0> { enum { value = 0 }; };
>>>
>>> During compilation of 'fib<2>::value' (after finally getting memoized
result of instantiation of struct fib<0>) Clang «instantiates the anonymous
enum inside fib<0> and fib<1>» 129 times in sum.
>>
>>
>> That sounds like a bug. How are you observing it?
>
>
> I debugged the metaprogram with use of Metashell tool.

Possibly this is a bug in metashell? How does it get this information?

>>> In case, when we use 'constexpr static auto' instead of 'enum', no
additional instantiations occurs. Why Clang performs additional
instantiations in the first case?
>>>
>>> Thank you,
>>> Pavel
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141013/8425a377/attachment.html>


More information about the cfe-dev mailing list