<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 - -Wunused-member-function default move"
href="https://bugs.llvm.org/show_bug.cgi?id=42196">42196</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Wunused-member-function default move
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>m-llvm@bodyfour.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Note this is similar to #25084, but I believe it is distinct, since it involves
-Wunused-member-function instead of -Wunneeded-member-function
Take this code for example:
namespace {
class F {
public:
explicit F(int x) : x_(x)
{
}
F(const F&) = default;
F& operator=(const F&) = default;
F(F&&) = default;
F& operator=(F&&) = default;
int get() const { return x_; }
private:
int x_;
};
}
int main(void)
{
F f(123);
return f.get();
}
Compiling it reveals these warnings:
$ bin/clang --std=c++11 -fsyntax-only -Wunused-member-function
rvalue-moveop-unused.cpp
rvalue-moveop-unused.cpp:10:2: warning: unused member function 'F'
[-Wunused-member-function]
F(F&&) = default;
^
rvalue-moveop-unused.cpp:11:5: warning: unused member function 'operator='
[-Wunused-member-function]
F& operator=(F&&) = default;
^
So it complains about the "=default" move operator/ctor being unused.
Interestingly, it does not do the same for the "=default" *copy* operator/ctor
even though it's just as unused.
Ultimately this warning isn't very useful, since it's complaining about a
function that isn't actually defined but just indicates that the same copy/move
that the class gets by default can be used.
This is especially annoying when these annotations are added via compiler
macros, since it means you get warnings whenever a class is put into the
anonymous namespace.
I'm far from an expert on clang internals, but I can see that the warning is
generated by lib/Sema/Sema.cpp which does:
if (!Diags.hasErrorOccurred() && TUKind != TU_Module) {
[...]
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
const FunctionDecl *DiagD;
if (!FD->hasBody(DiagD))
DiagD = FD;
if (DiagD->isDeleted())
continue; // Deleted functions are supposed to be unused.
So maybe it should also include ->isDeleted() there? Or maybe ->isTrivial()
too? But it's not clear to me why this affects move-ctor and not copy-ctor.</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>