https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110187
Bug ID: 110187
Summary: The compiler fails to warn about deleted constructor
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: amir.ahmed.ansari at outlook dot com
Target Milestone: ---
Created attachment 55293
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55293&action=edit
Code to replicate the problem
Compile the attached code with the following flags:
-std=c++17 -Wall -pedantic -Wextra -Weffc++ -O3 -flto
The program compiles successfully. Now attempt to create an object of type B as
auto b = B{};
Now the compiler spits errors (see below). This is very confusing for an
ordinary user. It becomes worse if B has a second constructor that initializes
a and this second constructor is used everywhere. This can lurk in the codebase
undetected until somebody finally instantiates B with the default constructor.
And it gets even worse when B is passed as a template argument and the error is
generated deep within the template instantiation.
<source>: In function 'int main()':
<source>:17:16: error: use of deleted function 'B::B()'
17 | auto b = B{};
| ^
<source>:9:5: note: 'B::B()' is implicitly deleted because the default
definition would be ill-formed:
9 | B() = default;
| ^
<source>:9:5: error: no matching function for call to 'A::A()'
<source>:3:5: note: candidate: 'A::A(int)'
3 | A(int) {}
| ^
<source>:3:5: note: candidate expects 1 argument, 0 provided
<source>:1:7: note: candidate: 'constexpr A::A(const A&)'
1 | class A
| ^
<source>:1:7: note: candidate expects 1 argument, 0 provided
<source>:1:7: note: candidate: 'constexpr A::A(A&&)'
<source>:1:7: note: candidate expects 1 argument, 0 provided