r197445 - For -Wconsumed, walk the namespaces to find if the top most namespace is "std"
Richard Trieu
rtrieu at google.com
Mon Dec 16 16:40:41 PST 2013
Author: rtrieu
Date: Mon Dec 16 18:40:40 2013
New Revision: 197445
URL: http://llvm.org/viewvc/llvm-project?rev=197445&view=rev
Log:
For -Wconsumed, walk the namespaces to find if the top most namespace is "std"
to determine if a move function is the std::move function. This allows functions
like std::__1::move to also be treated a the move function.
Modified:
cfe/trunk/lib/Analysis/Consumed.cpp
cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp
Modified: cfe/trunk/lib/Analysis/Consumed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Consumed.cpp?rev=197445&r1=197444&r2=197445&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/Consumed.cpp (original)
+++ cfe/trunk/lib/Analysis/Consumed.cpp Mon Dec 16 18:40:40 2013
@@ -605,14 +605,25 @@ void ConsumedStmtVisitor::VisitBinaryOpe
}
}
+static bool isStdNamespace(const DeclContext *DC) {
+ if (!DC->isNamespace()) return false;
+ while (DC->getParent()->isNamespace())
+ DC = DC->getParent();
+ const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
+
+ return ND && ND->getName() == "std" &&
+ ND->getDeclContext()->isTranslationUnit();
+}
+
void ConsumedStmtVisitor::VisitCallExpr(const CallExpr *Call) {
if (const FunctionDecl *FunDecl =
dyn_cast_or_null<FunctionDecl>(Call->getDirectCallee())) {
// Special case for the std::move function.
// TODO: Make this more specific. (Deferred)
- if (FunDecl->getQualifiedNameAsString() == "std::move" &&
- Call->getNumArgs() == 1) {
+ if (Call->getNumArgs() == 1 &&
+ FunDecl->getNameAsString() == "move" &&
+ isStdNamespace(FunDecl->getDeclContext())) {
forwardInfo(Call->getArg(0), Call);
return;
}
Modified: cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp?rev=197445&r1=197444&r2=197445&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp Mon Dec 16 18:40:40 2013
@@ -798,6 +798,12 @@ namespace std {
void move();
template<class T>
void move(T&&);
+
+ namespace __1 {
+ void move();
+ template<class T>
+ void move(T&&);
+ }
}
namespace PR18260 {
@@ -810,5 +816,7 @@ namespace PR18260 {
x.move();
std::move();
std::move(x);
+ std::__1::move();
+ std::__1::move(x);
}
} // end namespace PR18260
More information about the cfe-commits
mailing list