[PATCH] Warn, if parameter is used in ctor body after being used for move-construct
David Blaikie
dblaikie at gmail.com
Thu Jun 25 11:46:38 PDT 2015
+rtrieu
On Fri, Jun 12, 2015 at 3:53 PM, Ismail Pazarbasi <
ismail.pazarbasi at gmail.com> wrote:
> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150625/27843b73/attachment.html>
More information about the cfe-commits
mailing list