Author: Chuanqi Xu Date: 2021-12-29T16:22:26+08:00 New Revision: 8de2d06251c30751bdc0fd7b89133610797759e6
URL: https://github.com/llvm/llvm-project/commit/8de2d06251c30751bdc0fd7b89133610797759e6 DIFF: https://github.com/llvm/llvm-project/commit/8de2d06251c30751bdc0fd7b89133610797759e6.diff LOG: [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`. Added: Modified: clang/lib/Sema/SemaOverload.cpp clang/test/SemaTemplate/constraints.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 42b1340f9a65d..a268837b3cc86 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -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); diff --git a/clang/test/SemaTemplate/constraints.cpp b/clang/test/SemaTemplate/constraints.cpp index 0bc4727245f6a..e2bb6552fdb1c 100644 --- a/clang/test/SemaTemplate/constraints.cpp +++ b/clang/test/SemaTemplate/constraints.cpp @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits