[PATCH] D87229: [SyntaxTree] Ignore implicit `CXXFunctionalCastExpr` wrapping constructor
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 8 02:45:16 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG134455a07c1f: [SyntaxTree] Ignore implicit `CXXFunctionalCastExpr` wrapping constructor (authored by eduucaldas).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87229/new/
https://reviews.llvm.org/D87229
Files:
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===================================================================
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -4069,7 +4069,6 @@
X(int);
};
X test() {
- // FIXME: Remove `UnknownExpression` due to implicit `CXXFunctionalCastExpr`
[[return X(1);]]
}
)cpp",
@@ -4077,12 +4076,11 @@
ReturnStatement Statement
|-'return' IntroducerKeyword
|-UnknownExpression ReturnValue
-| `-UnknownExpression
-| |-'X'
-| |-'('
-| |-IntegerLiteralExpression
-| | `-'1' LiteralToken
-| `-')'
+| |-'X'
+| |-'('
+| |-IntegerLiteralExpression
+| | `-'1' LiteralToken
+| `-')'
`-';'
)txt"}));
}
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===================================================================
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -14,6 +14,7 @@
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/OperationKinds.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/TypeLoc.h"
@@ -60,9 +61,25 @@
return E;
}
+// In:
+// struct X {
+// X(int)
+// };
+// X x = X(1);
+// Ignores the implicit `CXXFunctionalCastExpr` that wraps
+// `CXXConstructExpr X(1)`.
+static Expr *IgnoreCXXFunctionalCastExprWrappingConstructor(Expr *E) {
+ if (auto *F = dyn_cast<CXXFunctionalCastExpr>(E)) {
+ if (F->getCastKind() == CK_ConstructorConversion)
+ return F->getSubExpr();
+ }
+ return E;
+}
+
static Expr *IgnoreImplicit(Expr *E) {
return IgnoreExprNodes(E, IgnoreImplicitSingleStep,
- IgnoreImplicitConstructorSingleStep);
+ IgnoreImplicitConstructorSingleStep,
+ IgnoreCXXFunctionalCastExprWrappingConstructor);
}
LLVM_ATTRIBUTE_UNUSED
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87229.290438.patch
Type: text/x-patch
Size: 1924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200908/7bd74841/attachment.bin>
More information about the cfe-commits
mailing list