Inherited alias not visible to template?

This code works just fine:
http://coliru.stacked-crooked.com/a/01104ebeeee1be3f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
template<typename T>
struct ReallyVerboseName
{
    ReallyVerboseName(T const &){}
    virtual ~ReallyVerboseName() = default;
};

template<typename T>
struct Derived1
: virtual ReallyVerboseName<T>
{
    using RVN_t = ReallyVerboseName<T>;
    virtual ~Derived1() = 0;
};
template<typename T>
Derived1<T>::~Derived1<T>() = default;

//template<typename T>
struct Derived2
: Derived1</*T*/int>
{
    Derived2(/*T*/int const &t)
    : RVN_t(t)
    {
    }
};

int main()
{
    Derived2/*<int>*/{7};
}
However, as soon as I make Derived2 a template, it fails to compile:
http://coliru.stacked-crooked.com/a/6ad9a828b6afe6b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
template<typename T>
struct ReallyVerboseName
{
    ReallyVerboseName(T const &){}
    virtual ~ReallyVerboseName() = default;
};

template<typename T>
struct Derived1
: virtual ReallyVerboseName<T>
{
    using RVN_t = ReallyVerboseName<T>;
    virtual ~Derived1() = 0;
};
template<typename T>
Derived1<T>::~Derived1<T>() = default;

template<typename T>
struct Derived2
: Derived1<T>
{
    Derived2(T const &t)
    : RVN_t(t)
    {
    }
};

int main()
{
    Derived2<int>{7};
}
main.cpp:24:7: error: member initializer 'RVN_t' does not name a non-static data member or base class
    : RVN_t(t)
      ^~~~~~~~
What's going on here?
Last edited on
closed account (10X9216C)
1
2
3
4
5
...

: Derived1<T>::RVN_t(t)
{
}


That seems to resolve the issue (if that's what you were looking for), not entirely sure why but seems like it might be a restriction with templates (or maybe a bug).
> What's going on here?

Two phase name-lookup.
The compiler does not treat RVN_t as a dependent name.
http://www.cplusplus.com/forum/beginner/103508/#msg557627
http://www.parashift.com/c++-faq/nondependent-name-lookup-types.html

1
2
3
4
5
6
7
8
9
10
template<typename T>
struct Derived2
: Derived1<T>
{
    using typename Derived1<T>::RVN_t ; // *** added
    Derived2(T const &t)
    : RVN_t(t) // now, RVN_t is a dependant name
    {
    }
};

http://coliru.stacked-crooked.com/a/e744c6a415db6fb3
closed account (10X9216C)
Ah so would what I have above be considered part of "temporary" solution compilers accept, or is that a special case where it can be determined that it's not a static variable?
Ah, I was thinking it had to do with dependent names. Thanks JLBorges! That solution preserves the terseness I was going for.
Topic archived. No new replies allowed.