[PATCH] Warn, if parameter is used in ctor body after being used for move-construct
Ismail Pazarbasi
ismail.pazarbasi at gmail.com
Fri Jun 12 15:53:17 PDT 2015
Hi rsmith, dblaikie,
If a member of type unique_ptr or shared_ptr is move-constructed from
a parameter in ctor-init, the parameter will be left with nullptr at
the completion of member's initialization. If the parameter's and
member's names are the same, use of member's name in the constructor
body will not refer to the member, but to the parameter.
#include <memory>
struct X {
int v;
X() : v() { }
int f() { return v + 42; }
};
struct Y {
std::unique_ptr<X> p;
int x;
explicit Y(std::unique_ptr<X> p)
: p{std::move(p)} {
x = p->f(); // 'p' is nullptr
decltype(p->f()) v = x; // ignore unevaluated context
}
int f() const { return x; }
};
int main() {
std::unique_ptr<X> p(new X);
Y y(std::move(p));
return y.f();
}
http://reviews.llvm.org/D10425
Files:
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaCXX/rval-references.cpp
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10425.27614.patch
Type: text/x-patch
Size: 8604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150612/4c4b2ac8/attachment.bin>
More information about the cfe-commits
mailing list