Skip to Main Content

DevOps, CI/CD and Automation

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

kovalAug 4 2017 — edited Aug 6 2017

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

#include <type_traits>


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;



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;)

Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 3 2017
Added on Aug 4 2017
1 comment