On Wed, Mar 4, 2009 at 9:12 PM, Simon Hill <[email protected]> wrote:
> g++ doesn't seem able to match a template ctor of a template class
> where the ctor input is an internal class defined inside any template
> class.
>
> I briefly skimmed the titles of the current regression issues and I
> didn't notice any that matched this, but I'm not 100% sure.
>
> I first posted this here thinking it was my code that was somehow wrong.
> http://www.gamedev.net/community/forums/topic.asp?topic_id=526736
>
> demo.cpp
> ========================
> template <typename T>
> class CFoo
> {
> public:
> class CZep {};
>
> CFoo(int); // line 7.
> template <typename Z> CFoo(typename CFoo<Z>::CZep); // ## ctor I want ##
> ~CFoo();
>
> CZep zep();
> };
>
>
> int main()
> {
> CFoo<int> x(1);
> CFoo<int>::CZep z;
> CFoo<int> w(z); // line 19: ## should call the ctor on line 8 ##
>
> return 0;
> }
>
> ========================
>
> g++ demo.cpp
> ========================
> demo.cpp: In function ‘int main()’:
> demo.cpp:19: error: no matching function for call to
> ‘CFoo<int>::CFoo(CFoo<int>::CZep&)’
> demo.cpp:7: note: candidates are: CFoo<T>::CFoo(int) [with T = int]
> demo.cpp:3: note: CFoo<int>::CFoo(const CFoo<int>&)
> ========================
>
> Specs:
> g++ [4.4.0]
> ubuntu [ibex, 64]
>
>
> This compiles fine on 3.3.2 and MSVC according to other testers at
> gamedev.net.
>
>
> Note: In the above example CZep is inside CFoo, but it doesn't matter
> if you put CZep inside class CBar<T> {} instead, just as long as it's
> inside another template class.
>
>
>
> Does the above code compile OK on other people's 4.4.0s? or is it a bug?
EDG says
t.C(8): warning #488: template parameter "Z" is not used in declaring
the parameter types of function template
"CFoo<T>::CFoo<Z>(CFoo<Z>::CZep)"
template <typename Z> CFoo(typename CFoo<Z>::CZep); // ## ctor I want ##
^
t.C(8): warning #488: template parameter "Z" is not used in declaring
the parameter types of function template
"CFoo<T>::CFoo<Z>(CFoo<Z>::CZep) [with T=int]"
template <typename Z> CFoo(typename CFoo<Z>::CZep); // ## ctor I want ##
^
detected during instantiation of class "CFoo<T> [with
T=int]" at line 17
t.C(19): error: no instance of constructor "CFoo<T>::CFoo [with
T=int]" matches the argument list
argument types are: (CFoo<int>::CZep)
CFoo<int> w(z); // line 19: ## should call the ctor on line 8 ##
^
compilation aborted for t.C (code 2)
MSVC wasn't ever a good source of C++ validity testing. Basically during
instantiation of CFoo<int> the templated constructor is not instantiated and
thus not found.
Richard.