[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
This commit is contained in:
Adam Czachorowski 2021-06-09 14:52:29 +02:00
parent cc86b87a57
commit a95937452f
4 changed files with 17 additions and 1 deletions

View File

@ -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);

View File

@ -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:

View File

@ -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());

View File

@ -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