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

Richard Smith richard at metafoo.co.uk
Sun Oct 12 16:53:26 PDT 2014


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?

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/20141012/fc0a5299/attachment.html>


More information about the cfe-dev mailing list