public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/22520] New: g++ treats object declaration as function declaration (rejects valid program)
@ 2005-07-17 14:04 ccarena at cox dot net
  2005-07-17 14:25 ` [Bug c++/22520] " ccarena at cox dot net
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ccarena at cox dot net @ 2005-07-17 14:04 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/22520] g++ treats object declaration as function declaration (rejects valid program)
  2005-07-17 14:04 [Bug c++/22520] New: g++ treats object declaration as function declaration (rejects valid program) ccarena at cox dot net
@ 2005-07-17 14:25 ` ccarena at cox dot net
  2005-07-17 15:56 ` pinskia at gcc dot gnu dot org
  2005-07-17 16:31 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: ccarena at cox dot net @ 2005-07-17 14:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ccarena at cox dot net  2005-07-17 14:04 -------
This change will make it work:

  Degrees degrees180( OneEighty );

  Angle angle1( Degrees(180.0    ));// an instance of Angle
  Angle angle2( degrees180 );       // this will work now


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22520


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/22520] g++ treats object declaration as function declaration (rejects valid program)
  2005-07-17 14:04 [Bug c++/22520] New: g++ treats object declaration as function declaration (rejects valid program) ccarena at cox dot net
  2005-07-17 14:25 ` [Bug c++/22520] " ccarena at cox dot net
@ 2005-07-17 15:56 ` pinskia at gcc dot gnu dot org
  2005-07-17 16:31 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-17 15:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-17 15:56 -------


*** This bug has been marked as a duplicate of 18000 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22520


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/22520] g++ treats object declaration as function declaration (rejects valid program)
  2005-07-17 14:04 [Bug c++/22520] New: g++ treats object declaration as function declaration (rejects valid program) ccarena at cox dot net
  2005-07-17 14:25 ` [Bug c++/22520] " ccarena at cox dot net
  2005-07-17 15:56 ` pinskia at gcc dot gnu dot org
@ 2005-07-17 16:31 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-17 16:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-17 15:57 -------
Forgot to mention GCC is right, see [8.2] of the standard.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22520


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-07-17 15:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-17 14:04 [Bug c++/22520] New: g++ treats object declaration as function declaration (rejects valid program) ccarena at cox dot net
2005-07-17 14:25 ` [Bug c++/22520] " ccarena at cox dot net
2005-07-17 15:56 ` pinskia at gcc dot gnu dot org
2005-07-17 16:31 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).