https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129270
Bug ID: 129270
Summary: [C++20] GCC accepts use of a deleted copy constructor
when a less constrained overload exists
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: konstantin.vladimirov at gmail dot com
Target Milestone: ---
GCC accepts the following program without a diagnostic.
Reproducer (repro.cpp)
template<bool B>
struct S {
S(const S&) {} // #1
S(const S&) requires (B) = delete; // #2
};
void copy(const S<true>& src) {
S<true> dst(src);
}
Compiler and target
GCC 14.2.0 (Debian 14.2.0-19), x86_64-linux-gnu
Commands
g++ -std=c++20 -fsyntax-only repro.cpp
g++ -std=c++23 -fsyntax-only repro.cpp
Actual result
Both commands exit with status 0 and produce no diagnostics.
Expected result
GCC should diagnose the use of the deleted copy constructor #2.
For S<true>, both constructors are viable and have identical
parameter types. Constructor #2 is more constrained, so it is
the best viable function. Since #2 is deleted, the initialization
is ill-formed. Overload resolution cannot fall back to #1.
See C++23 draft N4950, [over.match.best.general]/2.6
and [dcl.fct.def.delete]/2.