c++ - Is typename required or not here? -
consider code:
#include <memory> template <class t, class deleter = std::default_delete<t>> class unique_ptr_wrapper: public std::unique_ptr<t, deleter> { public: using typename std::unique_ptr<t, deleter>::unique_ptr; operator t* () const {return this->get();} }; int main() { unique_ptr_wrapper<int> upw{new int{42}}; }
g++5.1 compiles fine, although clang++ complains
error: typename allowed identifiers only
i agree don't have identifier here, typename
not required. forbidden? compiler required @ least emit diagnostic?
edit code compiled fine without typename
both g++ , clang++.
update seems g++ bug, reported here.
[class.inhctor]/p1, emphasis mine:
a using-declaration (7.3.3) names constructor implicitly declares set of inheriting constructors.
a constructor not type.
[temp.res]/p3-4:
3 when qualified-id intended refer type not member of current instantiation (14.6.2.1) , nested-name-specifier refers dependent type, shall prefixed keyword
typename
, forming typename-specifier. if qualified-id in typename-specifier not denote type, program ill-formed.4 if specialization of template instantiated set of template-arguments such qualified-id prefixed
typename
not denote type, specialization ill-formed. usual qualified name lookup (3.4.3) used find qualified-id in presence oftypename
.
[class.qual]/p2:
in lookup in function names not ignored , nested-name-specifier nominates class
c
:
if name specified after nested-name-specifier, when looked in
c
, injected-class-name ofc
(clause 9), orin using-declaration (7.3.3) member-declaration, if name specified after nested-name-specifier same identifier or simple-template-id’s template-name in last component of nested-name-specifier,
the name instead considered name constructor of class
c
.
applying "usual qualified name lookup" rules found in [class.qual], std::unique_ptr<t, deleter>::unique_ptr
names constructor. not denote type. therefore, above quote [temp.res], program ill-formed (with diagnostic required).
in other words, appears gcc bug (though clang's error message use improvement too).
Comments
Post a Comment