This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/22520] New: g++ treats object declaration as function declaration (rejects valid program)
- From: "ccarena at cox dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Jul 2005 13:58:35 -0000
- Subject: [Bug c++/22520] New: g++ treats object declaration as function declaration (rejects valid program)
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This is actually applicable to every version of g++ I have on my system, not
just 4.0.1. I am tempted to say I have it wrong, but the only difference between
the two object declarations is how a constant is expressed.
g++ treats these two object declarations as different:
Angle angle1( Degrees(180.0 ));// an instance of Angle
Angle angle2( Degrees(OneEighty));// declaration of a func??
where
const double OneEighty = 180.0;
The following line is rejected because angle2 isn't an instance of Angle, but is
being treated as a function declaration, incorrectly, I think:
angle1 += angle2; // won't compile because angle2 isn't an Angle
The whole program follows:
///////////////////////////////////////////////start
const double OneEighty = 180.0;
struct Degrees
{
double m_Degrees;
Degrees( const double & degrees )
:
m_Degrees( degrees )
{
}
};
struct Angle
{
double m_Degrees;
Angle(const Degrees & degree)
:
m_Degrees( degree.m_Degrees )
{
}
Angle & operator+=(const Angle & rhs)
{
m_Degrees += rhs.m_Degrees;
return *this;
}
};
void test(void)
{
Angle angle1( Degrees(180.0 ));// an instance of Angle
Angle angle2( Degrees(OneEighty));// declaration of a func??
//
// The following line fails
// on the compilers on my system of the following versions:
// gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-126)
// gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
// gcc version 3.4.0 (Red Hat Linux 3.4.0-1)
// gcc version 4.0.0
// gcc version 4.0.1 20050617 (prerelease)
//
angle1 += angle2; // won't compile because angle2 isn't an Angle
//
// The following two types from typeid are not equal
//
// printf("typeid(angle1).name() = \"%s\"\n",
// typeid(angle1).name()
// );
// printf("typeid(angle2).name() = \"%s\"\n",
// typeid(angle2).name()
// );
}
///////////////////////////////////////////// end
--
Summary: g++ treats object declaration as function declaration
(rejects valid program)
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ccarena at cox dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22520