https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118054
Bug ID: 118054
Summary: GCC allows catch-by-value using trivial move
constructor
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hstong at ca dot ibm.com
Target Milestone: ---
GCC allows catch-by-copy for classes with deleted copy constructors but trivial
move constructors.
Online compiler: https://godbolt.org/z/5cx354qvM
### SOURCE (<stdin>)
struct Base {
Base() = default;
Base(const Base &) = delete;
Base(Base &&) = default;
};
struct A : Base {
A() = default;
A(const A &) : Base() {}
A(A &&) = default;
};
void bar(), foo(Base *);
int main() {
try {
bar();
} catch (Base b) {
foo(&b);
}
}
### COMPILE COMMAND
g++ -fsyntax-only -std=c++11 -xc++ -
### ACTUAL COMPILE OUTPUT
(clean compile)
### EXPECTED COMPILE OUTPUT
<stdin>: In function 'int main()':
<stdin>:15:17: error: use of deleted function 'Base::Base(const Base&)'
<stdin>:3:3: note: declared here
<stdin>:15:17: note: use '-fdiagnostics-all-candidates' to display considered
candidates
### COMPILER VERSION INFO (g++ -v)
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.0 20241214 (experimental) (GCC)