[llvm-bugs] [Bug 42196] New: -Wunused-member-function default move
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jun 8 12:29:08 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=42196
Bug ID: 42196
Summary: -Wunused-member-function default move
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: m-llvm at bodyfour.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190608/390632de/attachment.html>
More information about the llvm-bugs
mailing list