[PATCH] PR16182 - Visit parameter declaration of implicitly declared copy assignment operator.
Michael Han
fragmentshaders at gmail.com
Wed Jun 12 10:35:41 PDT 2013
Rename VisitsParmVarDecl to VisitsParmVarDeclForImplicitCode and add comments to explain what this test is doing.
Hi klimek, rsmith,
http://llvm-reviews.chandlerc.com/D958
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D958?vs=2361&id=2373#toc
Files:
unittests/Tooling/RecursiveASTVisitorTest.cpp
unittests/Tooling/TestVisitor.h
lib/Sema/SemaDeclCXX.cpp
Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===================================================================
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -35,6 +35,15 @@
}
};
+class ParmVarDeclVisitorForImplicitCode :
+ public ExpectedLocationVisitor<ParmVarDeclVisitorForImplicitCode> {
+public:
+ bool VisitParmVarDecl(ParmVarDecl *ParamVar) {
+ Match(ParamVar->getNameAsString(), ParamVar->getLocStart());
+ return true;
+ }
+};
+
class CXXMemberCallVisitor
: public ExpectedLocationVisitor<CXXMemberCallVisitor> {
public:
@@ -106,6 +115,20 @@
}
};
+// Test RAV visits parameter variable declaration of implicit
+// copy assignment operator.
+TEST(RecursiveASTVisitor, VisitsParmVarDeclForImplicitCode) {
+ ParmVarDeclVisitorForImplicitCode Visitor;
+ // Match parameter variable name of implicit copy assignment operator.
+ // This parameter name does not have a valid IdentifierInfo, and shares
+ // same SourceLocation with its class declaration, so we match an empty name
+ // with class source location here.
+ Visitor.ExpectMatch("", 1, 7);
+ EXPECT_TRUE(Visitor.runOver(
+ "class X {};\n"
+ "void foo(X a, X b) {a = b;}"));
+}
+
TEST(RecursiveASTVisitor, VisitsBaseClassDeclarations) {
TypeLocVisitor Visitor;
Visitor.ExpectMatch("class X", 1, 30);
Index: unittests/Tooling/TestVisitor.h
===================================================================
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -31,7 +31,7 @@
/// This is a drop-in replacement for RecursiveASTVisitor itself, with the
/// additional capability of running it over a snippet of code.
///
-/// Visits template instantiations (but not implicit code) by default.
+/// Visits template instantiations and implicit code by default.
template <typename T>
class TestVisitor : public RecursiveASTVisitor<T> {
public:
@@ -55,6 +55,10 @@
return true;
}
+ bool shouldVisitImplicitCode() const {
+ return true;
+ }
+
protected:
virtual ASTFrontendAction* CreateTestAction() {
return new TestAction(this);
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -8788,14 +8788,24 @@
FunctionProtoType::ExtProtoInfo EPI;
EPI.ExceptionSpecType = EST_Unevaluated;
EPI.ExceptionSpecDecl = CopyAssignment;
- CopyAssignment->setType(Context.getFunctionType(RetType, ArgType, EPI));
+ QualType T = Context.getFunctionType(RetType, ArgType, EPI);
+ CopyAssignment->setType(T);
+ // PR16182. Build type source info for copy assignment operator. RAV relies on
+ // type source info to traverse parameter declaration of implicit
+ // declared copy assignment operator.
+ TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, ClassLoc);
+ CopyAssignment->setTypeSourceInfo(TSInfo);
+ UnqualTypeLoc UnQualTL = TSInfo->getTypeLoc().getUnqualifiedLoc();
+ FunctionTypeLoc FTL = UnQualTL.getAs<FunctionTypeLoc>();
+
// Add the parameter to the operator.
ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyAssignment,
ClassLoc, ClassLoc, /*Id=*/0,
ArgType, /*TInfo=*/0,
SC_None, 0);
CopyAssignment->setParams(FromParam);
+ FTL.setArg(0, FromParam);
AddOverriddenMethods(ClassDecl, CopyAssignment);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D958.2.patch
Type: text/x-patch
Size: 3524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130612/bb1aae97/attachment.bin>
More information about the cfe-commits
mailing list