This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,831 Users
  • 2,269,775 Discussions
  • 7,916,823 Comments

Discussions

'Template cannot be specialized after it has been instantiated' error for inner class

koval
koval Member Posts: 72 Blue Ribbon

Studio 12.6 started giving error for the code which compiled fine with 12.5

#include <type_traits>template<typename>struct Traits {    enum { IsA = false, IsB = false };};struct A1{};struct A2{};template<typename T>class C {    // This is where Traits<T> gets instantiated    struct L: std::conditional<Traits<T>::isA || Traits<T>::isB, A1, A2>::type {};};struct D {    struct I {};    C<I> ci;};template<>struct Traits<D::I> {    enum { isA = true, isB = false };};

The error:

"test.cpp", line 23: Error: Template "Traits<D::I>" cannot be specialized after it was instantiated."test.cpp", line 23: Error: Invalid template nesting depth.

Is this a bug or a new interpretation of the standard?

Note that the error disappears when Traits is a forward declaration only before class C (template<typename> struct Traits;)

koval

Answers

  • Steve.Clamage-Oracle
    Steve.Clamage-Oracle Oracle Studio C++ Project Lead Santa Clara, CA, USAMember Posts: 775
    edited Aug 6, 2017 5:52PM

    Thanks for reporting this problem. I have filed C++ compiler bug .26580982 for you.

    If you have a service contract with Oracle, you can request a fix in a patch, via your support channel. In any case, we will fix it as resources permit.

    kovalkoval
This discussion has been closed.