[PATCH] D87229: [SyntaxTree] Ignore implicit `CXXFunctionalCastExpr` wrapping constructor
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 05:41:22 PDT 2020
eduucaldas updated this revision to Diff 290261.
eduucaldas added a comment.
Add comments
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
@@ -4066,7 +4066,6 @@
X(int);
};
X test() {
- // FIXME: Remove `UnknownExpression` due to implicit `CXXFunctionalCastExpr`
[[return X(1);]]
}
)cpp",
@@ -4074,12 +4073,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.290261.patch
Type: text/x-patch
Size: 1924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200907/fec6217e/attachment.bin>
More information about the cfe-commits
mailing list