Re: specialized templates not working as expected

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 19 Feb 2020 at 19:48, andre maute <andre.maute@xxxxxx> wrote:
>
> Hi list,
>
> I have the following code,
> which compiles with MSVC 19.14 (godbolt.org),
> but DOESN'T on a recent g++ (see below).
>
> Am I missing something here?
> Activating the marked block makes it compilable for g++.
>
> I understand that this is a template instantiation problem.
> But I'm wondering why there is such a difference
> in standard interpretation for such an old C++ feature.

Either MSVC has a bug, or it chooses to use the end of the file as the
point of instantiation for all templates. The latter is allowed by the
standard.


> I also understand that there are other possibilities
> to achieve a similar effect, but I don't like to discuss
> these possibilities here.

So then what's the question?

The code says "can this block be simplified or even removed?" and the
answer's yes, but you said you don't want to discuss that.

If you reorder the specializations so that A<int>::A() comes last then
it compiles with GCC (and Clang and EDG). The problem is that
A<int>::A() triggers the implicit instantiation of the other member
functions, before the specializations have been seen. By reordering
them the specializations have been defined before the instantiation
happens.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux