diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -14706,6 +14706,8 @@ First, Callee->getBeginLoc(), Second, OpLoc); } else if (Op == OO_Arrow) { // -> is never a builtin operation. + if (First->getType()->isDependentType()) + return ExprError(); return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); } else if (Second == nullptr || isPostIncDec) { if (!First->getType()->isOverloadableType() || diff --git a/clang/test/SemaCXX/arrow-operator.cpp b/clang/test/SemaCXX/arrow-operator.cpp --- a/clang/test/SemaCXX/arrow-operator.cpp +++ b/clang/test/SemaCXX/arrow-operator.cpp @@ -65,3 +65,25 @@ } } // namespace arrow_suggest + +namespace no_crash_dependent_type { + +template +struct A { + void call(); + A* operator->(); +}; + +template +void foo() { + // x is dependent. + A& x = blah[7]; // expected-error {{use of undeclared identifier 'blah'}} \ + // expected-error {{declaration of reference variable 'x' requires an initializer}} + x->call(); +} + +void test() { + foo(); // expected-note {{in instantiation}} +} + +} // namespace no_crash_dependent_type