This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/36982] Unfolding of template function (in namespace) using overloads (in same namespace) requires forward declarations
- From: "bangerth at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Apr 2009 22:05:10 -0000
- Subject: [Bug c++/36982] Unfolding of template function (in namespace) using overloads (in same namespace) requires forward declarations
- References: <bug-36982-16537@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from bangerth at gmail dot com 2009-04-02 22:05 -------
Andrew is right:
> static inline bool Read( const char* Str, int& v )
> { v = 0; return true; }
>
> template< class T >
> static inline bool Read( const char* Str, std::vector< T >& v )
> {
> T Help;
> if ( !Read( Str, Help ) )
Upon seeing the template, the compiler determines the set of possible
overloads for the call to Read() -- which consists of the function we're
in right now as well as Read(const char*,int&). Upon instantiation with
T=MyType, it adds to this list the set of functions named Read from the
namespace in which MyType was declared -- i.e. the global namespace, in which
no such function is found. So the overload set remains what it was. As a
consequence, no overload is found.
The fact that other compilers, including earlier versions of gcc, get this
wrong is immaterial.
W.
> return false;
> v.push_back( Help );
> return true;
> }
> }
>
> struct MyType
> {
> int i;
> };
>
> namespace ReadSpace // Extend the namespace ...
> {
> static inline bool Read( const char* Str, MyType& v )
> { return Read( Str, v.i ); }
> }
>
> using namespace ReadSpace;
>
> int main()
> {
> std::vector< MyType > v;
> const char* Str = "25";
> return Read( Str, v ) ? 0 : 1;
> }
>
--
bangerth at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36982