Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is `using Base::operator T` allowed where `T` is a template type parameter?

Consider this example:

struct B { operator int(); };

template<class T>
struct X:B
{
    using B::operator T;
};

GCC accepts the code, while Clang and MSVC rejects it. Which is correct?

Note that if the base type is dependent, all the compilers accept the code:

template<class T>
struct B { operator T(); };

template<class T>
struct X:B<T>
{
    using B<T>::operator T;
};
like image 593
Jamboree Avatar asked Jul 27 '16 09:07

Jamboree


People also ask

What is template parameter in C++?

A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function.

What does template typename t mean?

" typename " is a keyword in the C++ programming language used when writing templates. It is used for specifying that a dependent name in a template definition or declaration is a type.


1 Answers

I think GCC is right, in §7.3.3/1, we can find:

The set of declarations introduced by the using-declaration is found by performing qualified name lookup (3.4.3, 10.2) for the name in the using-declaration, excluding functions that are hidden as described below.

I don't see any reason why operator T would not be found, actually:

template<class T>
struct X: B {
    T f () { return B::operator T; }
};

...compiles fine with g++ and clang (did not test on MSVC).

I cannot find anything in the standard specific to conversion functionsfor qualified name lookup except:

Since specializations of member templates for conversion functions are not found by name lookup, they are not considered when a using-declaration specifies a conversion function (14.5.2).

But B::operator int is not a specialization of a member function template, so it should not be taken into account by the above.

like image 54
Holt Avatar answered Oct 16 '22 07:10

Holt