Re: Behavior of constructor with default arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 1 Feb 2025 at 08:59, Creeperxie via Gcc-help
<gcc-help@xxxxxxxxxxx> wrote:
>
> Dear list,
>
> I would like to discuss the behavior of constructors with default
> arguments in
> GCC.
>
> In Clang, if a constructor redeclared with a default argument, it throws an
> error, indicating the constructor has become a default constructor. The
> early
> detection helps prevent potential issues for users.
>
> Here is an example to illustrate the issue.
>
> class Example {
>      Example(int arg);
>      Example(float arg);
> };
>
> Example::Example(int arg = 0) {
> }
>
> Example::Example(float arg = 0) {
> }
>
> When compiled with Clang, the following error is generated:
>
> error: addition of default argument on redeclaration makes this
> constructor a default constructor
>
> Will GCC consider implementing a similar warning for this situation?

Please file a bug https://gcc.gnu.org/bugs

In C++11 the code above was valid, but it's ill-formed since C++14. It
looks like GCC never implemented that change.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux