From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F332E384A076; Fri, 21 Oct 2022 08:46:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F332E384A076 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666341979; bh=SLgXzMvdnMFlIBnwvw0jO05wFgQP9kck9b9D3+vvcO8=; h=From:To:Subject:Date:From; b=tydCwNIHI5xMb3m3474qGFIIlEexgFxCtLuyDA3ek8xrVItzIIP8GK8q6tglhsoru +1Lx7tIuDS5U+e51S+mNtUUdYwyg4RzGDuEgjxRQ+B3WxL/0ja90s1muEsEYmNWj4q kyk1de0rpg7O+XgkCagAA7cM5+w/p4hLcHRafzXM= From: "jlame646 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107343] New: GCC accepts ill-formed out of class definition program Date: Fri, 21 Oct 2022 08:46:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jlame646 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107343 Bug ID: 107343 Summary: GCC accepts ill-formed out of class definition program Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jlame646 at gmail dot com Target Milestone: --- The following ill-formed program is accepted by gcc and msvc. Demo: https://godbolt.org/z/9PhnbYhb3 ``` class complex { public: complex (double r, double i); complex ();=20 complex(const complex &c); complex add(complex &c); void norm1(); private: double re, im;=20 double norm; }; //this is ill-formed as it turned it into default ctor complex::complex(double r=3D0.0, double i=3D0.0){=20 re =3D r; im =3D i;=20 norm1(); }; complex::complex(){ re=3Dim=3D0; } complex::complex(const complex &c){ re=3Dc.re; im=3Dc.im; } void complex::norm1(){ norm =3D sqrt(re*re + im*im); }; complex complex::add(complex &c){ return complex( re + c.re, im + c.im); }; int main(){ complex c1(3,4), c2(1,2); return 0; } ``` According to https://en.cppreference.com/w/cpp/language/default_arguments > For a member function of a non-template class, the default arguments are = allowed on the out-of-class definition, and are combined with the default a= rguments provided by the declaration inside the class body. If these out-of= -class defaults would turn a member function into a default constructor or = copy/move (since C++11) constructor/assignment operator, the program is ill= -formed.=