This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Strange "No matching function for call" compilation error with G++ 4.1
Yuanfei guo wrote:
> Hi there,
>
> Just resend this letter again with adding reproduction code. Any
> comments/suggestions are higly appreciated.
Now that really helps :)
>
> I am porting some code to SUSE 10, with G++ 4.1. And hit an strange
> "no matching function call" compilation error. I am confused because
> the calling function and candidate are nearly 100% same.
>
> I wonder if this is a known G++ limitation or issue ? Because the same
> program got compiled with VC8.
>
> Below is the compilation environment info and compilation error.
>
> env info
> =========
> g++ (GCC) 4.1.0 (SLES10), can also be found with g++ 3.2 (UL1.0)
>
> No compile option is added
>
>
> Compilation error
> =================
> no matching function for call to tdat_hash_map<MemAllocator<int>
>> ::func(MemAllocator<int>)
>
> main.cpp:6: note: candidates are: static void
> tdat_hash_map<_AllocType>::func(_AllocType&)
> [with _AllocType = MemAllocator<int>]
>
>
> Repro code
> ===========
> template <class Type> class MemAllocator{};
>
> template <class _AllocType> class tdat_hash_map {
> public:
> typedef _AllocType _Alloc;
> static void func(_Alloc&) {};
> };
>
> int main()
> {
> typedef tdat_hash_map<MemAllocator<int> > Map;
> Map::func((MemAllocator<int>) (MemAllocator<int>()));
>
> return 0;
> }
>
>
>
Replace main with:
int main()
{
typedef tdat_hash_map<MemAllocator<int> > Map;
MemAllocator<int> ma;
Map::func(ma);
return 0;
}
You were trying to get a reference to a temporary object by just calling
the constructor of MemAllocator where func expects a MemAllocator&.
The error message kind of contains this info as it says that it can't
find func(MemAllocator), note no reference.
A more intuitive error message would be nicer, I guess. E.g. icc9.1
tells you:
testKelvin.cpp(12): error: initial value of reference to non-const must
be an lvalue
Map::func((MemAllocator<int>) (MemAllocator<int>()));
And Comeau (http://www.comeaucomputing.com/tryitout/) says the exact
same thing (hmm, is icc using the EDG front-end now?)
Note that even if VC8 decided to compile this code it most likely
wouldn't work properly. OTOH maybe you meant to pass a const ref anyway?
HTH, Peter
>
> Thanks,
> -Kelvin
>
>
> On 9/27/06, Yuanfei guo <yuanfei8077@gmail.com> wrote:
>> Hi there,
>>
>> I am porting some code to SUSE 10, with G++ 4.1. And hit an strange
>> "no matching function call" compilation error. I am confused because
>> the calling function and candidate are nearly 100% same.
>>
>> I wonder if this is a known G++ limitation or issue ? Because the same
>> program got compiled with VC8.
>>
>> Below is the compilation environment info and compilation error.
>>
>> env info
>> =========
>> g++ (GCC) 4.1.0 (SUSE Linux)
>>
>> No compile option is added
>>
>>
>> Compilation error
>> ==============
>> ./Cache/CacheManager.h:424: error: no matching function for call to
>> tdat_hash_map<std::basic_string<wchar_t, std::char_traits<wchar_t>,
>> std::allocator<wchar_t> >, Element<unsigned int, SqlObjectDefn,
>> std::basic_string<wchar_t, std::char_traits<wchar_t>,
>> std::allocator<wchar_t> > >*,
>> MemAllocator<std::pair<std::basic_string<wchar_t,
>> std::char_traits<wchar_t>, std::allocator<wchar_t> >, Element<unsigned
>> int, SqlObjectDefn, std::basic_string<wchar_t,
>> std::char_traits<wchar_t>, std::allocator<wchar_t> > >*> >
>> >::tdat_hash_map1(MemAllocator<std::pair<std::basic_string<wchar_t,
>> std::char_traits<wchar_t>, std::allocator<wchar_t> >, Element<unsigned
>> int, SqlObjectDefn, std::basic_string<wchar_t,
>> std::char_traits<wchar_t>, std::allocator<wchar_t> > >*> >, int)
>>
>> ./Common/TdatHashMap.h:250: note: candidates are: static void
>> tdat_hash_map<_Key, _Tp, _AllocType>::tdat_hash_map1(_AllocType&, int)
>> [with _Key = std::basic_string<wchar_t, std::char_traits<wchar_t>,
>> std::allocator<wchar_t> >, _Tp = Element<unsigned int, SqlObjectDefn,
>> std::basic_string<wchar_t, std::char_traits<wchar_t>,
>> std::allocator<wchar_t> > >*, _AllocType =
>> MemAllocator<std::pair<std::basic_string<wchar_t,
>> std::char_traits<wchar_t>, std::allocator<wchar_t> >, Element<unsigned
>> int, SqlObjectDefn, std::basic_string<wchar_t,
>> std::char_traits<wchar_t>, std::allocator<wchar_t> > >*> >]
>>
>>
>>
>> Any comments/suggestions are higly appreciated.
>>
>> Thanks,
>> -Kelvin
>>