public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107343] New: GCC accepts ill-formed out of class definition program
@ 2022-10-21 8:46 jlame646 at gmail dot com
2022-10-21 9:05 ` [Bug c++/107343] " jlame646 at gmail dot com
0 siblings, 1 reply; 2+ messages in thread
From: jlame646 at gmail dot com @ 2022-10-21 8:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107343
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 ();
complex(const complex &c);
complex add(complex &c);
void norm1();
private:
double re, im;
double norm;
};
//this is ill-formed as it turned it into default ctor
complex::complex(double r=0.0, double i=0.0){
re = r; im = i;
norm1();
};
complex::complex(){
re=im=0;
}
complex::complex(const complex &c){
re=c.re;
im=c.im;
}
void complex::norm1(){
norm = 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 arguments 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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/107343] GCC accepts ill-formed out of class definition program
2022-10-21 8:46 [Bug c++/107343] New: GCC accepts ill-formed out of class definition program jlame646 at gmail dot com
@ 2022-10-21 9:05 ` jlame646 at gmail dot com
0 siblings, 0 replies; 2+ messages in thread
From: jlame646 at gmail dot com @ 2022-10-21 9:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107343
--- Comment #1 from Jason Liam <jlame646 at gmail dot com> ---
The complete quote at the end of my original post is as follows:
> 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 arguments 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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-21 9:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 8:46 [Bug c++/107343] New: GCC accepts ill-formed out of class definition program jlame646 at gmail dot com
2022-10-21 9:05 ` [Bug c++/107343] " jlame646 at gmail dot com
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).