[llvm-branch-commits] [cfe-branch] r205784 - Merging r197445:

Tom Stellard thomas.stellard at amd.com
Tue Apr 8 11:57:42 PDT 2014


Author: tstellar
Date: Tue Apr  8 13:57:41 2014
New Revision: 205784

URL: http://llvm.org/viewvc/llvm-project?rev=205784&view=rev
Log:
Merging r197445:

------------------------------------------------------------------------
r197445 | rtrieu | 2013-12-16 19:40:40 -0500 (Mon, 16 Dec 2013) | 4 lines

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/branches/release_34/lib/Analysis/Consumed.cpp
    cfe/branches/release_34/test/SemaCXX/warn-consumed-analysis.cpp

Modified: cfe/branches/release_34/lib/Analysis/Consumed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/Analysis/Consumed.cpp?rev=205784&r1=205783&r2=205784&view=diff
==============================================================================
--- cfe/branches/release_34/lib/Analysis/Consumed.cpp (original)
+++ cfe/branches/release_34/lib/Analysis/Consumed.cpp Tue Apr  8 13:57:41 2014
@@ -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/branches/release_34/test/SemaCXX/warn-consumed-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/test/SemaCXX/warn-consumed-analysis.cpp?rev=205784&r1=205783&r2=205784&view=diff
==============================================================================
--- cfe/branches/release_34/test/SemaCXX/warn-consumed-analysis.cpp (original)
+++ cfe/branches/release_34/test/SemaCXX/warn-consumed-analysis.cpp Tue Apr  8 13:57:41 2014
@@ -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 llvm-branch-commits mailing list