From: Richard Trieu Date: Thu, 27 Nov 2014 01:29:32 +0000 (+0000) Subject: When checking for uninitialized values, do not confuse "std::move" with every X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=abd574ee5ff726dd7560fcda33c6c0582c9128ae;p=clang When checking for uninitialized values, do not confuse "std::move" with every other function named "move". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222863 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 94f59f196e..61a259217d 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -419,7 +419,8 @@ void ClassifyRefs::VisitCallExpr(CallExpr *CE) { // Classify arguments to std::move as used. if (CE->getNumArgs() == 1) { if (FunctionDecl *FD = CE->getDirectCallee()) { - if (FD->getIdentifier() && FD->getIdentifier()->isStr("move")) { + if (FD->isInStdNamespace() && FD->getIdentifier() && + FD->getIdentifier()->isStr("move")) { classify(CE->getArg(0), Use); return; } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 08f5c3c8b8..d299ec1e57 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8489,7 +8489,8 @@ namespace { // Treat std::move as a use. if (E->getNumArgs() == 1) { if (FunctionDecl *FD = E->getDirectCallee()) { - if (FD->getIdentifier() && FD->getIdentifier()->isStr("move")) { + if (FD->isInStdNamespace() && FD->getIdentifier() && + FD->getIdentifier()->isStr("move")) { HandleValue(E->getArg(0)); return; } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 5ffe30883b..583357e234 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2511,7 +2511,8 @@ namespace { // Treat std::move as a use. if (E->getNumArgs() == 1) { if (FunctionDecl *FD = E->getDirectCallee()) { - if (FD->getIdentifier() && FD->getIdentifier()->isStr("move")) { + if (FD->isInStdNamespace() && FD->getIdentifier() && + FD->getIdentifier()->isStr("move")) { HandleValue(E->getArg(0), false /*AddressOf*/); return; } diff --git a/test/SemaCXX/uninitialized.cpp b/test/SemaCXX/uninitialized.cpp index ac08183a70..018b1feba9 100644 --- a/test/SemaCXX/uninitialized.cpp +++ b/test/SemaCXX/uninitialized.cpp @@ -1341,3 +1341,47 @@ struct D : public C, public A { }; } + +namespace value { +template T move(T t); +template T notmove(T t); +} +namespace lvalueref { +template T move(T& t); +template T notmove(T& t); +} +namespace rvalueref { +template T move(T&& t); +template T notmove(T&& t); +} + +namespace move_test { +int a1 = std::move(a1); // expected-warning {{uninitialized}} +int a2 = value::move(a2); // expected-warning {{uninitialized}} +int a3 = value::notmove(a3); // expected-warning {{uninitialized}} +int a4 = lvalueref::move(a4); +int a5 = lvalueref::notmove(a5); +int a6 = rvalueref::move(a6); +int a7 = rvalueref::notmove(a7); + +void test() { + int a1 = std::move(a1); // expected-warning {{uninitialized}} + int a2 = value::move(a2); // expected-warning {{uninitialized}} + int a3 = value::notmove(a3); // expected-warning {{uninitialized}} + int a4 = lvalueref::move(a4); + int a5 = lvalueref::notmove(a5); + int a6 = rvalueref::move(a6); + int a7 = rvalueref::notmove(a7); +} + +class A { + int a; + A(int (*) [1]) : a(std::move(a)) {} // expected-warning {{uninitialized}} + A(int (*) [2]) : a(value::move(a)) {} // expected-warning {{uninitialized}} + A(int (*) [3]) : a(value::notmove(a)) {} // expected-warning {{uninitialized}} + A(int (*) [4]) : a(lvalueref::move(a)) {} + A(int (*) [5]) : a(lvalueref::notmove(a)) {} + A(int (*) [6]) : a(rvalueref::move(a)) {} + A(int (*) [7]) : a(rvalueref::notmove(a)) {} +}; +}