1

This is not a duplicate of this question.

Below, I list my base class as well as how I am deriving a class from it:

template<template<size_t, typename...> typename D>
struct Modifier
{
    // some static variables
};

template<typename M, size_t U, typename T, typename... S>
struct Base
{
    // some implementations
};

template<size_t U, typename T>
struct Derived;

template<>
struct Modifier<Derived>;

template<size_t U, typename T>
struct Derived : Base<Modifier<Derived>, U, T, double>
{
    using Base<Modifier<Derived>, U, T, double>::Base;
};

To provide some context, the idea is that the implementation of Base will access some static variables from M in order to change the behaviour of a couple of functions.

When I compile this with msvc (build tools v142), it complains about:

1>...: error C3210:  'Base<Modifier<Derived<2,unsigned __int64> >,2,unsigned __int64,double>': a member using-declaration can only be applied to a base class member
1>...: error C3881:  can only inherit constructor from direct base

Yet, when I introduce using mod_t = Modifier<Derived>; and apply that in the implementation of Derived instead of the full name, it correctly compiles.

By the way, whether I define Derived like above or like:

template<size_t U, typename T>
struct Derived : Base<Modifier<Derived>, U, T, double>
{
    using parent_type = Base<Modifier<Derived>, U, T, double>;
    using parent_type::Base;
};

or

template<size_t U, typename T>
struct Derived : Base<Modifier<Derived>, U, T, double>
{
    using parent_type = Base<Modifier<Derived>, U, T, double>;
    using parent_type::parent_type;
};

I will still get an error.

What am I missing here?

Riddick
  • 319
  • 3
  • 15
  • This seems like compiler bug. Clang builds it just fine. Note, that you need c++17 for template template typename parameter. – Radosław Cybulski Jun 11 '19 at 09:45
  • MSVC will build it as long as it doesn't get instantiated. It was my assumption too considering the silliness of the workaround. This is msvc 2019, and I use similar constructs elsewhere in my code, its only this case that gives me issues. Is this something I should submit on their bug report? – Riddick Jun 11 '19 at 09:47
  • 1
    I just instatiated Derived class and clang still builds it just fine. Gcc also builds it without problems. Looks like compiler bug. – Radosław Cybulski Jun 11 '19 at 09:50

1 Answers1

0

This issue (with msvc) is actually related to my previous question here:

Simpler work-around to avoid injected-class-name is to use full name.

In the above, Derived needs to be prefixed as ::Derived and this will then successfully compile.

Riddick
  • 319
  • 3
  • 15