Hello! I have FreeBSD 8.0-BETA4.
Why this

#include <iostream>
template <typename T, unsigned int (T::*)() const>
class TSizeEnabler { public: typedef T TClass; };

template <typename X> unsigned int GetAllSize(const X &Var)
   { return sizeof(Var); }
template <typename X> unsigned int GetAllSize(const typename TSizeEnabler<X,
&X::CalcMySize>::TClass &Var)
   { return Var.CalcMySize(); }

template <typename T>
class THash
   {
      public:
      T Var;
      unsigned int CalcMySize() const { return 42 + GetAllSize<T>(Var); }
   };
int main()
   {
      int a;
      THash<int> b;
      std::cout << GetAllSize<int>(a) << std::endl;
      std::cout << GetAllSize< THash<int> >(b) << std::endl;
      return 0;
   }


works well at gcc 3.4.6 but fails at gcc 4.2.1 and gcc 4.5.0.20091008 with
these messages:
gcc 4.5.0.2009100 output:
%g++45 -std=c++0x main.cpp
main.cpp: In function 'int main()':
main.cpp:24:46: error: call of overloaded 'GetAllSize(THash<int>&)' is
ambiguous
main.cpp:6:36: note: candidates are: unsigned int GetAllSize(const X&) [with X
= THash<int>]
main.cpp:8:36: note: unsigned int GetAllSize(const typename TSizeEnabler<X, (&
X::CalcMySize)>::TClass&) [with X = THash<int>, typename TSizeEnabler<X, (&
X::CalcMySize)>::TClass = THash<int>]
%
And gcc 4.2.1 output:
%g++ main.cpp
main.cpp: In function 'int main()':
main.cpp:23: error: call of overloaded 'GetAllSize(THash<int>&)' is ambiguous
main.cpp:5: note: candidates are: unsigned int GetAllSize(const X&) [with X =
THash<int>]
main.cpp:7: note:                 unsigned int GetAllSize(const typename
TSizeEnabler<X, (& X::CalcMySize)>::TClass&) [with X = THash<int>]
%


And how i can fix it the problem?
Thanks.


-- 
           Summary: Problems with SFINAE. Source works at gcc 3.4.6 but
                    fails at 4.2.1 and 4.5.0.20091008
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: DimanNe at ya dot ru


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41703

Reply via email to