https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86250

            Bug ID: 86250
           Summary: addition of default argument on redeclaration makes
                    this constructor a default constructor
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

//#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();
}

clang++ rejects, and produces the following error messages:
error: addition of default argument on redeclaration makes this constructor a
default constructor
    Z::Z(int j=43): i(j){}
             ^ ~~
note: previous declaration is here

A previous version of gcc also rejects the code. The bug report is
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2189

I reported this problem to clang: https://bugs.llvm.org/show_bug.cgi?id=37869

Richard Smith determined that the test case is ill-formed. So, is this a bug in
gcc, since it accepts ill-formed code?

Reply via email to