[clang] Fix crash in bug52905

The root cause for the crash is the incorrect use of `cast`.
The actual type and cast-to type is different. This patch fixes the
crash by converting the `cast` to `dyn_cast`.
This commit is contained in:
Chuanqi Xu 2021-12-29 16:22:26 +08:00
parent b4682816bc
commit 8de2d06251
2 changed files with 36 additions and 3 deletions

View File

@ -14322,8 +14322,7 @@ ExprResult Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
FoundDecl = MemExpr->getFoundDecl();
Qualifier = MemExpr->getQualifier();
UnbridgedCasts.restore();
} else {
UnresolvedMemberExpr *UnresExpr = cast<UnresolvedMemberExpr>(NakedMemExpr);
} else if (auto *UnresExpr = dyn_cast<UnresolvedMemberExpr>(NakedMemExpr)) {
Qualifier = UnresExpr->getQualifier();
QualType ObjectType = UnresExpr->getBaseType();
@ -14436,7 +14435,9 @@ ExprResult Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
}
MemExpr = cast<MemberExpr>(MemExprE->IgnoreParens());
}
} else
// Unimaged NakedMemExpr type.
return ExprError();
QualType ResultType = Method->getReturnType();
ExprValueKind VK = Expr::getValueKindForType(ResultType);

View File

@ -24,3 +24,35 @@ namespace PR45589 {
// FIXME: These diagnostics are excessive.
static_assert(test<false, char> == 1); // expected-note 2{{while}} expected-note 2{{during}}
}
namespace PR52905 {
// A mock for std::convertible_to. Not complete support.
template <typename _From, typename _To>
concept convertible_to = __is_convertible_to(_From, _To); // expected-note {{evaluated to false}}
template <typename T>
class A {
public:
using iterator = void **;
iterator begin();
const iterator begin() const;
};
template <class T>
concept Beginable1 = requires(T t) {
{ t.begin }
->convertible_to<typename T::iterator>; // expected-note {{not satisfied}}
};
static_assert(Beginable1<A<int>>); // expected-error {{static_assert failed}}
// expected-note@-1 {{does not satisfy 'Beginable1'}}
template <class T>
concept Beginable2 = requires(T t) {
{ t.begin() }
->convertible_to<typename T::iterator>;
};
static_assert(Beginable2<A<int>>);
} // namespace PR52905