This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Possible 4.4.0 regression (can't match template ctor of template class where...)
- From: Sebastian Redl <sebastian dot redl at getdesigned dot at>
- To: Simon Hill <yacwroy at gmail dot com>
- Cc: gcc <gcc at gcc dot gnu dot org>
- Date: Wed, 04 Mar 2009 21:39:48 +0100
- Subject: Re: Possible 4.4.0 regression (can't match template ctor of template class where...)
- References: <fc3094d10903041212u7ac4fdr5baec2e7cc18cbb@mail.gmail.com>
Simon Hill 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();
> };
>
Imagine the compiler has to deal with this specialization of CFoo:
template <>
class CFoo<something> {
public:
typedef CFoo<int>::CZep CZep;
// otherwise identical
};
then the call
CFoo<something>::CZep cz;
CFoo<something> cf(cz);
is ambiguous - both of these are valid:
CFoo<something>::CFoo<something>(CFoo<something>::CZep)
CFoo<something>::CFoo<int>(CFoo<int>::CZep)
The language cuts this short, though. Containing types of types in the
argument do not take part in template argument deduction. Z cannot be
deduced from the arguments; it must be specified explicitly. Since
that's not possible for a constructor (or at least I don't know how),
the constructor is completely unusable.
GCC 4 is right here.
Sebastian