Skip to content
Latchkey

gcc/clang "use of deleted function" in CI

The function is marked = delete, or the compiler implicitly deleted it because a member or base cannot be copied, moved, or default-constructed. The call is forbidden.

What this error means

Copying, moving, or default-constructing a type fails with "use of deleted function", often for a class holding a std::unique_ptr or a std::mutex.

clang
app.cpp:9:14: error: use of deleted function 'Worker::Worker(const Worker&)'
note: 'Worker::Worker(const Worker&)' is implicitly deleted because the default
note: definition would copy 'std::unique_ptr<Impl>' which is non-copyable

Common causes

How to fix it

Move instead of copy, or define the operation

  1. Use std::move for move-only types instead of copying them.
  2. If copying is intended, give the class a meaningful copy constructor/assignment.
clang
Worker b = std::move(a);   // move-only: transfer, do not copy

How to prevent it

  • Treat types holding unique_ptr/mutex as move-only, and explicitly default or define the special members you intend to support.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →