c++ - Is it required to specify the template argument of a base class if the base class is a parameter type of a member function? -
the next code accepted vc++ 2013, rejected clang 3.4.
which compiler right per c++ standard?
template<class t> struct { t n; }; template<class t> struct b : a<t> { // vc++ 2013 : ok // clang : error : utilize of class template 'a' requires template arguments b& f1(const a& obj) { homecoming *this; } // vc++ : ok // clang : ok b& f2(const a<t>& obj) { homecoming *this; } }; int main() { b<int> b; }
my first instinct vc++ right in one. lookup of name a
in b
should find injected-class-name a
within a<t>
, can used type-name refer a<t>
.
c++11 [temp.local]:
1 normal (non-template) classes, class templates have injected-class-name (clause 9). injected-class-name can used template-name or type-name. when used template-argument-list, template-argument template template-parameter, or final identifier in elaborated-type-specifier of friend class template declaration, refers class template itself. otherwise, equivalent template-name followed template-parameters of class template enclosed in <>
.
2 ...
3 injected-class-name of class template or class template specialization can used either template-name or type-name wherever in scope. [ example:
template <class t> struct base of operations { base* p; }; template <class t> struct derived: public base<t> { typename derived::base* p; // meaning derived::base<t> };
however, @ same time, [temp.dep]§3 states:
3 in definition of class or class template, if base of operations class depends on template-parameter, base of operations class scope not examined during unqualified name lookup either @ point of definition of class template or fellow member or during instantiation of class template or member.
based on this, i'd more inclined clang right, since injected-class-name a
within scope of a<t>
, depends on b
's template parameter t
, not searched during unqualified name lookup. secondary evidence back upwards fact illustration [temp.local] uses derived::base
instead of base
.
so in total, i'd that
it's nice corner-case, and
clang right not examine scope of a<t>
c++ templates visual-c++ clang standards
No comments:
Post a Comment