[Bug c++/36982] New: Unfolding of template function (in namesspace) using overloads (in same namespace) requires forward declarations
lfn dot privat at mail dot dk
gcc-bugzilla@gcc.gnu.org
Thu Jul 31 08:31:00 GMT 2008
// The following self-contained code (see below, I dont know how to
// attach files to this report) produces the bug (see embedded comments).
//
// The command compiler command line and output is as this:
//
// g++ -c -O2 -I . -DSTATIC_BUILD -Wall x.cpp
// x.cpp: In function bool ReadSpace::Read(const char*,
// std::vector<T, // std::allocator<_Tp1> >&) [with T = MyType]:
// x.cpp:58: instantiated from here
// x.cpp:34: error: invalid initialization of reference of type
// int& from expression of type MyType
// x.cpp:27: error: in passing argument 2 of
// bool ReadSpace::Read(const char*, int&)
//
// Source code (x.cpp) ...
//
#include <vector>
/* <- Uncoment this block for GCC 4.3.1 workaround
//----------------------------------------------------------------------------
// Forward declarations needed by new GCC 4.3.1 compiler ...
//
// - Not needed by GCC 4.0.2 and previous versions !
// - Not needed by (Windows) MSC 8.0 (VS 2005) and previous versions !
//
// Note furthermore that IF everything is kept in the GLOBAL namespace,
// there is NO error - this, to me, indicates a GCC 4.3.1 compiler bug.
//
// LFN, 2008-07-31
//----------------------------------------------------------------------------
struct MyType;
namespace ReadSpace
{
static inline bool Read( const char* Str, MyType& v );
};
*/
namespace ReadSpace
{
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 ) )
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;
}
--
Summary: Unfolding of template function (in namesspace) using
overloads (in same namespace) requires forward
declarations
Product: gcc
Version: 4.3.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lfn dot privat at mail dot dk
GCC build triplet: Configured with: ../configure --prefix=/usr --with-
local-prefix=
GCC host triplet: gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch
revision
GCC target triplet: Target: i586-suse-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36982
More information about the Gcc-bugs
mailing list