Skip to content

Commit 10ce958

Browse files
author
Fariborz Jahanian
committed
self-referecing operator '->' member function was causing
infinit recursion. This patch fixes it. [13.3.1.2]-p2 llvm-svn: 83124
1 parent c210529 commit 10ce958

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,8 @@ def err_return_in_constructor_handler : Error<
16461646

16471647
def err_ident_in_pseudo_dtor_not_a_type : Error<
16481648
"identifier %0 in pseudo-destructor expression does not name a type">;
1649+
def err_operator_arrow_circular : Error<
1650+
"circular pointer delegation detected">;
16491651
def err_pseudo_dtor_base_not_scalar : Error<
16501652
"object expression of non-scalar type %0 cannot be used in a "
16511653
"pseudo-destructor expression">;

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,11 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc,
19821982
BaseExpr = (Expr*)Base.get();
19831983
if (BaseExpr == NULL)
19841984
return ExprError();
1985+
if (Context.getCanonicalType(BaseExpr->getType()) ==
1986+
Context.getCanonicalType(BaseType)) {
1987+
Diag(OpLoc, diag::err_operator_arrow_circular);
1988+
return ExprError();
1989+
}
19851990
BaseType = BaseExpr->getType();
19861991
}
19871992
}

clang/test/SemaCXX/overloaded-operator.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,14 @@ namespace M {
213213
struct AA { bool operator!=(AA&); };
214214
struct BB : AA {};
215215
bool x(BB y, BB z) { return y != z; }
216+
217+
218+
struct AX {
219+
AX& operator ->();
220+
int b;
221+
};
222+
223+
void m() {
224+
AX a;
225+
a->b = 0; // expected-error {{circular pointer delegation detected}}
226+
}

0 commit comments

Comments
 (0)