<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Dec 16, 2013 at 4:40 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rtrieu<br>
Date: Mon Dec 16 18:40:40 2013<br>
New Revision: 197445<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=197445&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=197445&view=rev</a><br>
Log:<br>
For -Wconsumed, walk the namespaces to find if the top most namespace is "std"<br>
to determine if a move function is the std::move function. This allows functions<br>
like std::__1::move to also be treated a the move function.<br>
<br>
Modified:<br>
cfe/trunk/lib/Analysis/Consumed.cpp<br>
cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp<br>
<br>
Modified: cfe/trunk/lib/Analysis/Consumed.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Consumed.cpp?rev=197445&r1=197444&r2=197445&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Consumed.cpp?rev=197445&r1=197444&r2=197445&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Analysis/Consumed.cpp (original)<br>
+++ cfe/trunk/lib/Analysis/Consumed.cpp Mon Dec 16 18:40:40 2013<br>
@@ -605,14 +605,25 @@ void ConsumedStmtVisitor::VisitBinaryOpe<br>
}<br>
}<br>
<br>
+static bool isStdNamespace(const DeclContext *DC) {<br>
+ if (!DC->isNamespace()) return false;<br>
+ while (DC->getParent()->isNamespace())<br>
+ DC = DC->getParent();<br></blockquote><div><br></div><div>You should only walk over inline namespaces here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);<br>
+<br>
+ return ND && ND->getName() == "std" &&<br>
+ ND->getDeclContext()->isTranslationUnit();<br>
+}<br>
+<br>
void ConsumedStmtVisitor::VisitCallExpr(const CallExpr *Call) {<br>
if (const FunctionDecl *FunDecl =<br>
dyn_cast_or_null<FunctionDecl>(Call->getDirectCallee())) {<br>
<br>
// Special case for the std::move function.<br>
// TODO: Make this more specific. (Deferred)<br>
- if (FunDecl->getQualifiedNameAsString() == "std::move" &&<br>
- Call->getNumArgs() == 1) {<br>
+ if (Call->getNumArgs() == 1 &&<br>
+ FunDecl->getNameAsString() == "move" &&<br></blockquote><div><br></div><div>Per the documentation, getNameAsString is human-readable (and deprecated), and not really appropriate for comparison. You can use FunDecl->getName().isIdentifier() && FunDecl->getName().getIdentifier()->isStr("move") instead.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ isStdNamespace(FunDecl->getDeclContext())) {<br>
forwardInfo(Call->getArg(0), Call);<br>
return;<br>
}<br>
<br>
Modified: cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp?rev=197445&r1=197444&r2=197445&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp?rev=197445&r1=197444&r2=197445&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp Mon Dec 16 18:40:40 2013<br>
@@ -798,6 +798,12 @@ namespace std {<br>
void move();<br>
template<class T><br>
void move(T&&);<br>
+<br>
+ namespace __1 {<br>
+ void move();<br>
+ template<class T><br>
+ void move(T&&);<br>
+ }<br>
}<br>
<br>
namespace PR18260 {<br>
@@ -810,5 +816,7 @@ namespace PR18260 {<br>
x.move();<br>
std::move();<br>
std::move(x);<br>
+ std::__1::move();<br>
+ std::__1::move(x);<br>
}<br>
} // end namespace PR18260<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>