[cfe-dev] Reason for Diagnostic on default ctors redeclaration

Alireza Moshtaghi Alireza.Moshtaghi at synopsys.com
Tue May 14 15:29:36 PDT 2013


Hi,
g++ accepts this code ,  but clang generates:
  error1.cpp:5:12:
  error: addition of default argument on redeclaration makes this
         constructor a default constructor
"
struct XX {
    int a;
    XX(int);
};
XX::XX(int c = 5) : a(c) { }
"
Question: where does this requirement come from ?

The diagnosis is generated in SemaDeclCXX.cpp:

// DR1344: If a default argument is added outside a class definition and that
// default argument makes the function a special member function, the program
// is ill-formed. This can only happen for constructors.
if (isa<CXXConstructorDecl>(New) &&
.......
}


Thanks
Ali

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130514/7576a18a/attachment.html>


More information about the cfe-dev mailing list