]> granicus.if.org Git - clang/commitdiff
self-referecing operator '->' member function was causing
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 30 Sep 2009 00:19:41 +0000 (00:19 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 30 Sep 2009 00:19:41 +0000 (00:19 +0000)
infinit recursion. This patch fixes it. [13.3.1.2]-p2

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83124 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExprCXX.cpp
test/SemaCXX/overloaded-operator.cpp

index 1d4e003e59e76d0120e0c7aff179ae2c6b880245..6843270ec0e95651ef24e6de7d46deae948664dc 100644 (file)
@@ -1646,6 +1646,8 @@ def err_return_in_constructor_handler : Error<
 
 def err_ident_in_pseudo_dtor_not_a_type : Error<
   "identifier %0 in pseudo-destructor expression does not name a type">;
+def err_operator_arrow_circular : Error<
+  "circular pointer delegation detected">;
 def err_pseudo_dtor_base_not_scalar : Error<
   "object expression of non-scalar type %0 cannot be used in a "
   "pseudo-destructor expression">;
index 3ca8849e6c280f5c76c3da411bd1fe676b36682e..fc32c3b3a6ff8a1f80267e2c08a09bcabcd7ffd8 100644 (file)
@@ -1982,6 +1982,11 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc,
       BaseExpr = (Expr*)Base.get();
       if (BaseExpr == NULL)
         return ExprError();
+      if (Context.getCanonicalType(BaseExpr->getType()) == 
+          Context.getCanonicalType(BaseType)) {
+        Diag(OpLoc, diag::err_operator_arrow_circular);
+        return ExprError();
+      }
       BaseType = BaseExpr->getType();
     }
   }
index 77b5d6c701087c57d533ec769864998f62ead82e..c849a145e2c4851e0ba203e08f61d2d249c6c572 100644 (file)
@@ -213,3 +213,14 @@ namespace M {
 struct AA { bool operator!=(AA&); };
 struct BB : AA {};
 bool x(BB y, BB z) { return y != z; }
+
+
+struct AX { 
+  AX& operator ->();
+  int b;
+}; 
+
+void m() {
+  AX a; 
+  a->b = 0; // expected-error {{circular pointer delegation detected}}
+}