This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/14250] New: switch() does not seem to see operator int() in template class
- From: "savoiu at ics dot uci dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Feb 2004 01:09:40 -0000
- Subject: [Bug c++/14250] New: switch() does not seem to see operator int() in template class
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
-- G++ INFO ---------------------------------------------------------------------------------------
Reading specs from /root/gcc/lib/gcc/i686-pc-linux-gnu/3.5.0/specs
Configured with: ../configure --prefix=/root/gcc --enable-languages=c++
Thread model: posix
gcc version 3.5.0 20040222 (experimental)
-- SOURCE CODE -------------------------------------------------------------------------------
#define USE_TEMPLATE
#ifndef USE_TEMPLATE
#define T unsigned int
#endif// USE_TEMPLATE
#ifdef USE_TEMPLATE
template <typename T>
#endif// USE_TEMPLATE
class O
{
T x;
public:
O(T _x=0)
{
}
O(const O& that)
{
x=that.x;
}
O& operator=(const O& that)
{
x=that.x;
return *this;
}
operator T() const
{
return x;
}
};
#ifdef USE_TEMPLATE
typedef O<unsigned int> MyO;
#else //USE_TEMPLATE
typedef O MyO;
#endif //USE_TEMPLATE
class C1
{
public:
static MyO t1;
class C2
{
public:
static MyO t2;
void fun()
{
switch(t2)
{
default:
break;
}
switch(C1::t1)
{
default:
break;
}
}
};
};
-- BUG INFO ---------------------------------------------------------------------------------------
Given the code above and running just g++ with no command line parameters I get:
[root@home temp]# g++ boog.cpp
boog.cpp: In member function `void C1::C2::fun()':
boog.cpp:53: error: switch quantity not an integer
boog.cpp:59: error: switch quantity not an integer
I expected g++ to see the 'operator T() const'. Note that if you comment out '#define
USE_TEMPLATE' then the code compiles OK.
This problem occurs on other versions of GCC as well (notably 3.3).
Cheers,
Nick
--
Summary: switch() does not seem to see operator int() in template
class
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: savoiu at ics dot uci dot edu
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14250