llvm / llvm/llvm-project

Missing notice for why not-actually-defaulted move ctor in template is unavailable

Open
#197,938 0 comments 0 reactions 0 assignees View on GitHub
new issue
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/Ys5G6v6YT

```c++
#include

class H {
public:
H(){}
H(const H&) = delete;
H(H&&) = delete;
};

template
class G {
public:
G(int) {}
G(const G&) = delete;
G(G&&) = default;
H h;
};

void foo()
{
G<1> g(5);
G<1> g2 = std::move(g);
}
```

Expected: Anything telling me why G(G&&) is unavailable. For example what Clang does if G isn't a template
```
:15:5: warning: explicitly defaulted move constructor is implicitly deleted [-Wdefaulted-function-deleted]
15 | G(G&&) = default;
| ^
:16:7: note: move constructor of 'G' is implicitly deleted because field 'h' has a deleted move constructor
16 | H h;
| ^
:7:5: note: 'H' has been explicitly marked deleted here
7 | H(H&&) = delete;
| ^
```

Actual: The complete error is
```
:22:10: error: call to deleted constructor of 'G<1>'
22 | G<1> g2 = std::move(g);
| ^ ~~~~~~~~~~~~
:14:5: note: 'G' has been explicitly marked deleted here
14 | G(const G&) = delete;
| ^
```

It's understandable to not print that warning if G's movability depends on its template args, but if an attempt is made to actually move an unmovable G, I'd prefer if its mctor's attempted existence is at least acknowledged.

(Originally found with a std::make_shared trying to call mctor on something containing a deeply nested std::atomic)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.