• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions


  • Subject: Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions
  • From: Ulrich Frotscher <email@hidden>
  • Date: Wed, 16 Nov 2005 11:25:01 +0100

Hi,
I am experiencing problems with Xcode 2.2 (gcc-4.0.1 build 5247) compiling code with overloaded template functions. gcc complains about ambiguous overloaded functions in the following code snippet. To recreate just create a new project of type "Command Line Utility/C+ + Tool", paste the snippet into main.cpp and build. The same code compiles fine with Xcode 2.1 (gcc 4.0.0), CodeWarrior, VC7, and Comeau (online compiler on http://www.comeaucomputing.com). I think the code is OK, if not I would be happy to learn more about this. Is this a bug in gcc 4.0.1? Did anyone see similar problems? What can I do to fix the problem?


//////////////////
// File main.cpp
#include <vector>
#include <string>

template< typename T1, typename T2 >
inline std::vector<T1> foo( const std::vector<T2>& t )
{
	std::vector<T1> t1;
	return t1;
}

template< typename T >
inline std::vector<T> foo(const std::vector<T>& t)
{
	return t;
}

std::vector<std::string> t()
{
	std::vector< std::string > t;
	return foo< std::string >( t );
}

int main (int argc, char * const argv[])
{
    t();
    return 0;
}
//////////////////
// EOF


By compiling this code snippet with Xcode 2.2 (gcc-4.0.1 build 5247) on Macintel I get the following error message:


[...]
In function 'std::vector<std::string, std::allocator<std::string> > t ()':
error: call of overloaded 'foo(std::vector<std::string, std::allocator<std::string> >&)' is ambiguous
note:
candidates are: std::vector<T1, std::allocator<_CharT> > foo(const std::vector<T2, std::allocator<_T2> >&) [with T1 = std::string, T2 = std::string]
note:
std::vector<T1, std::allocator<_CharT> > foo(const std::vector<T1, std::allocator<_CharT> >&) [with T = std::string]
[...]


The complete log:

Building target “main.cpp” of project “templatetest”

Checking Dependencies
CompileC /Users/admin/Documents/XCode21/intermediate/ templatetest.build/Debug/templatetest.build/Objects-normal/i386/ main.o /Users/admin/templatetest/main.cpp normal i386 c++ com.apple.compilers.gcc.4_0
cd /Users/admin/templatetest
/usr/bin/gcc-4.0 -x c++ -arch i386 -pipe -Wno-trigraphs -fpascal- strings -fasm-blocks -g -O0 -Wreturn-type -Wunused-variable -fmessage- length=0 -mfix-and-continue -Wno-invalid-offsetof -fvisibility- inlines-hidden -I/Users/admin/Documents/XCode21/intermediate/ templatetest.build/Debug/templatetest.build/templatetest.hmap -F/ Users/admin/Documents/XCode21/products/Debug -I/Users/admin/Documents/ XCode21/products/Debug/include -I/Users/admin/Documents/XCode21/ intermediate/templatetest.build/Debug/templatetest.build/ DerivedSources -isysroot /Developer/SDKs/MacOSX10.4u.sdk -c /Users/ admin/templatetest/main.cpp -o /Users/admin/Documents/XCode21/ intermediate/templatetest.build/Debug/templatetest.build/Objects- normal/i386/main.o
/Users/admin/templatetest/main.cpp: In function 'std::vector<std::string, std::allocator<std::string> > t()':
/Users/admin/templatetest/main.cpp:19: error: call of overloaded 'foo (std::vector<std::string, std::allocator<std::string> >&)' is ambiguous
/Users/admin/templatetest/main.cpp:5: note: candidates are: std::vector<T1, std::allocator<_CharT> > foo(const std::vector<T2, std::allocator<_T2> >&) [with T1 = std::string, T2 = std::string]
/Users/admin/templatetest/main.cpp:11: note: std::vector<T1, std::allocator<_CharT> > foo(const std::vector<T1, std::allocator<_CharT> >&) [with T = std::string]


Ulrich Frotscher


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions
      • From: Olivier Tristan <email@hidden>
  • Prev by Date: Re: simple user interface
  • Next by Date: Re: Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions
  • Previous by thread: Xcode jam error
  • Next by thread: Re: Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions
  • Index(es):
    • Date
    • Thread