[clang] a959374 - [clang] Make CXXDefaultArgExpr inherit dependence from the inner Expr
Adam Czachorowski via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 10 05:58:56 PDT 2021
Author: Adam Czachorowski
Date: 2021-06-10T14:51:08+02:00
New Revision: a95937452f237fad10e6b7e43154c17c6b8476c4
URL: https://github.com/llvm/llvm-project/commit/a95937452f237fad10e6b7e43154c17c6b8476c4
DIFF: https://github.com/llvm/llvm-project/commit/a95937452f237fad10e6b7e43154c17c6b8476c4.diff
LOG: [clang] Make CXXDefaultArgExpr inherit dependence from the inner Expr
Before this change, CXXDefaultArgExpr would always have
ExprDependence::None. This can lead to issues when, for example, the
inner expression is RecoveryExpr and yet containsErrors() on the default
expression is false.
Differential Revision: https://reviews.llvm.org/D103982
Added:
clang/test/AST/ast-dump-default-arg-dep.cpp
Modified:
clang/include/clang/AST/ComputeDependence.h
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ComputeDependence.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ComputeDependence.h b/clang/include/clang/AST/ComputeDependence.h
index 7dde42ee71ba0..8db09e6b57d0f 100644
--- a/clang/include/clang/AST/ComputeDependence.h
+++ b/clang/include/clang/AST/ComputeDependence.h
@@ -71,6 +71,7 @@ class OverloadExpr;
class DependentScopeDeclRefExpr;
class CXXConstructExpr;
class CXXDefaultInitExpr;
+class CXXDefaultArgExpr;
class LambdaExpr;
class CXXUnresolvedConstructExpr;
class CXXDependentScopeMemberExpr;
@@ -156,6 +157,7 @@ ExprDependence computeDependence(OverloadExpr *E, bool KnownDependent,
ExprDependence computeDependence(DependentScopeDeclRefExpr *E);
ExprDependence computeDependence(CXXConstructExpr *E);
ExprDependence computeDependence(CXXDefaultInitExpr *E);
+ExprDependence computeDependence(CXXDefaultArgExpr *E);
ExprDependence computeDependence(LambdaExpr *E,
bool ContainsUnexpandedParameterPack);
ExprDependence computeDependence(CXXUnresolvedConstructExpr *E);
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index c46f9bd7f4db0..2626f9b925962 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1257,7 +1257,7 @@ class CXXDefaultArgExpr final : public Expr {
Param->getDefaultArg()->getObjectKind()),
Param(Param), UsedContext(UsedContext) {
CXXDefaultArgExprBits.Loc = Loc;
- setDependence(ExprDependence::None);
+ setDependence(computeDependence(this));
}
public:
diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index 1a5d2f7075fb5..5648cf2103d64 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -748,6 +748,10 @@ ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) {
return E->getExpr()->getDependence();
}
+ExprDependence clang::computeDependence(CXXDefaultArgExpr *E) {
+ return E->getExpr()->getDependence();
+}
+
ExprDependence clang::computeDependence(LambdaExpr *E,
bool ContainsUnexpandedParameterPack) {
auto D = toExprDependence(E->getType()->getDependence());
diff --git a/clang/test/AST/ast-dump-default-arg-dep.cpp b/clang/test/AST/ast-dump-default-arg-dep.cpp
new file mode 100644
index 0000000000000..a804ac120fca4
--- /dev/null
+++ b/clang/test/AST/ast-dump-default-arg-dep.cpp
@@ -0,0 +1,10 @@
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump -frecovery-ast %s | FileCheck %s
+
+// CXXDefaultArgExpr should inherit dependence from the inner Expr, in this case
+// RecoveryExpr.
+void fun(int arg = foo());
+
+void test() {
+ fun();
+}
+// CHECK: -CXXDefaultArgExpr 0x{{[^ ]*}} <<invalid sloc>> '<dependent type>' contains-errors lvalue
More information about the cfe-commits
mailing list