<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - clang 12.0.0 ignores copy constructor and fails to compile seemingly correct code"
href="https://bugs.llvm.org/show_bug.cgi?id=50344">50344</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang 12.0.0 ignores copy constructor and fails to compile seemingly correct code
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>12.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>f.kazmin@corp.mail.ru
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=24857" name="attach_24857" title="code in question">attachment 24857</a> <a href="attachment.cgi?id=24857&action=edit" title="code in question">[details]</a></span>
code in question
Hello,
I have got an issue on move/copy ctors with clang 12.0.0 compliling my code
Version:
[root@trgbuild build]# clang++ -v
clang version 12.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-last/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Code:
struct test_t {
test_t(test_t&&) = delete;
test_t(const test_t&) {};
test_t() {};
};
test_t failing(void) {
test_t tmp;
return tmp;
}
int main(void) {
return 0;
}
Observed behaviour:
[root@trgbuild build]# clang++ movector.cpp
movector.cpp:9:12: error: call to deleted constructor of 'test_t'
return tmp;
^~~
movector.cpp:2:5: note: 'test_t' has been explicitly marked deleted here
test_t(test_t&&) = delete;
^
1 error generated.
Expected (by me) behaviour:
Compiles, provided copy constructor is used to return a value from function
Reasoning:
C++17 6.3.2/2:
<span class="quote">> [Note: A return statement can involve an invocation of a constructor to perform a
> copy or move of the operand if it is not a prvalue or if its type differs from the
> return type of the function.</span >
So, compliler can use a copy constructor on return statement
<a href="https://en.cppreference.com/w/cpp/language/move_constructor">https://en.cppreference.com/w/cpp/language/move_constructor</a>:
<span class="quote">> If only the copy constructor is provided, all argument categories select it
> (as long as it takes a reference to const, since rvalues can bind to const
> references), which makes copying the fallback for moving, when moving is
> unavailable.</span >
So, it should use copy ctor having move ctor deleted
Is it a bug or I simply misunderstand something?</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>