`typename` keyword before non-type template parameter defined via nested templated `using` in out-of-line member definition

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

 



I have trouble getting g++ and clang to agree on proper syntax for
declaring member out-of-line:

```
#include <type_traits>
#include <iostream>
#include <string>

template <typename T>
struct B {
    template <typename U>
    using nested_templated_using = U;

    template<typename U = T, nested_templated_using<U>* = nullptr >
    void f();
};

template <typename T>
template <typename U, typename B<T>::template
nested_templated_using<U>* > // should typename be present before B<T
>
void  B<T>::f(){ }

int main () { return 0;}
```

gcc does not want to compile the code with the salient `typename` present.

I've been told by clang guys, that formally for the match, the exact
token sequence must match + compiler are allowed to accept additional
cases. The most verbose example seems to be:

```
template <typename T>
struct B {
    template <typename U>
    using nested_templated_using = U;

    template<typename U = T, typename B<T>::template
nested_templated_using<U>* = nullptr >
    void f();
};

template <typename T>
template <typename U, typename B<T>::template nested_templated_using<U>* >
void  B<T>::f(){ }
```

But gcc needs the `typename` keyword before ` B<T>` in the definition
to be removed to match the declaration. From what I understand that
the need for the `typename` is debatable.

To my understanding this depends whether `nested_templated_using` in
the definition is considered a member of current instatation as
understood by [temp.res.#3](http://eel.is/c++draft/temp.res#3):

> When a qualified-id is intended to refer to a type that is not a member of the current instantiation ([temp.dep.type]) and its nested-name-specifier refers to a dependent type, it shall be prefixed by the keyword typename, forming a typename-specifier.
> If the qualified-id in a typename-specifier does not denote a type or a class template, the program is ill-formed

This seems to be debatable. However, presence of `typename` in this
context should be should be accepted, even if it's redundant.

Am I misunderstanding something, or should gcc accept the code? Here
is my playground on godbolt: https://godbolt.org/g/yjPH1u

It seems that one of the compilers in non-conformant, because they
accept the code in a mutually exclusive manner.

Regards,
Łukasz.




[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