adamcz created this revision.
adamcz added a reviewer: hokein.
Herald added a project: All.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121824

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/arrow-operator.cpp


Index: clang/test/SemaCXX/arrow-operator.cpp
===================================================================
--- clang/test/SemaCXX/arrow-operator.cpp
+++ clang/test/SemaCXX/arrow-operator.cpp
@@ -65,3 +65,25 @@
 }
 
 } // namespace arrow_suggest
+
+namespace no_crash_dependent_type {
+
+template<class T>
+struct A {
+  void call();
+  A* operator->();
+};
+
+template <class T>
+void foo() {
+  // x is dependent.
+  A<int>& 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<int>();  // expected-note {{in instantiation}}
+}
+
+} // namespace no_crash_dependent_type
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ 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() ||


Index: clang/test/SemaCXX/arrow-operator.cpp
===================================================================
--- clang/test/SemaCXX/arrow-operator.cpp
+++ clang/test/SemaCXX/arrow-operator.cpp
@@ -65,3 +65,25 @@
 }
 
 } // namespace arrow_suggest
+
+namespace no_crash_dependent_type {
+
+template<class T>
+struct A {
+  void call();
+  A* operator->();
+};
+
+template <class T>
+void foo() {
+  // x is dependent.
+  A<int>& 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<int>();  // expected-note {{in instantiation}}
+}
+
+} // namespace no_crash_dependent_type
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ 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() ||
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to