public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/2189: g++ rejects legal code
@ 2002-07-04  8:07 lerdsuwa
  0 siblings, 0 replies; 2+ messages in thread
From: lerdsuwa @ 2002-07-04  8:07 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, mayer, nobody

Synopsis: g++ rejects legal code

State-Changed-From-To: analyzed->closed
State-Changed-By: lerdsuwa
State-Changed-When: Thu Jul  4 08:07:39 2002
State-Changed-Why:
    Fixed in GCC 3.0.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=2189


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

* c++/2189: g++ rejects legal code
@ 2001-04-01  0:00 mayer
  0 siblings, 0 replies; 2+ messages in thread
From: mayer @ 2001-04-01  0:00 UTC (permalink / raw)
  To: gcc-gnats; +Cc: mayer

>Number:         2189
>Category:       c++
>Synopsis:       g++ rejects legal code
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 05 14:06:02 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Uwe F. Mayer
>Release:        2.97 20010205 (experimental)
>Organization:
tux.org
>Environment:
System: Linux tosca 2.2.18 #1 Sun Feb 25 14:33:05 PST 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-20010205/configure --prefix=/usr/local/gcc --disable-nls
>Description:
g++ rejects the following legal code (file bug3.cc), which has a
constructor initializer with default value and a declaration of this
constructor without the default value. The default value is the provided
in the definition. The file bug3.cc:

//#include <iostream>
//using namespace std;
class Z {
public:
  // gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) allows to
  // write Z(int) while gcc version 2.97 20010205 wants Z(int j=43)
  Z(int);
  //void print ();
private:
  int i;
};
Z::Z(int j=43): i(j){}
//void Z::print(void){ cout << "Z : i= " << i << ".\n";}

int main()
{
   Z zobject=Z();
   //zobject.print();
}
>How-To-Repeat:
Run "g++ bug3.cc". I get:
bug3.cc: In function `int main()':
bug3.cc:17: no matching function for call to `Z::Z()'
bug3.cc:3: candidates are: Z::Z(const Z&)
bug3.cc:12:                 Z::Z(int)

Please note that an earlier version of g++ accepted this code. I do not
know whether this behavior change of g++ was planned due to adherence to
some new standard. If so, please forget about this bug report.
Here is bug3.ii, just in case it is a bug:

# 3 "bug3.cc"
class Z {
public:


  Z(int);

private:
  int i;
};
Z::Z(int j=43): i(j){}


int main()
{
   Z zobject=Z();

}
>Fix:
Provide the default value in the declaration. For the example above, that
amounts to writing:
class Z {
public:
  Z(int j=43);
private:
  int i;
};
Z::Z(int j=43): i(j){};
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-07-04 15:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-04  8:07 c++/2189: g++ rejects legal code lerdsuwa
  -- strict thread matches above, loose matches on Subject: below --
2001-04-01  0:00 mayer

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).