From 95110968dcd6ba2baef2a23549cd5592f01eca59 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Fri, 28 Mar 2008 21:37:05 +0000 Subject: [PATCH] Make sure Sema::ActOnClassMessage() correctly diagnoses "super". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48924 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticKinds.def | 2 ++ lib/Sema/SemaExprObjC.cpp | 5 ++++- test/Sema/undef-superclass-1.m | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index c3825624e4..a6e6529e5f 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -477,6 +477,8 @@ DIAG(error_missing_method_context, ERROR, "missing context for method declaration") DIAG(error_bad_receiver_type, ERROR, "bad receiver type '%0'") +DIAG(error_no_super_class, ERROR, + "no super class declared in @interface for '%0'") //===----------------------------------------------------------------------===// // Semantic Analysis diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 4cf435c331..1a274e126e 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -146,7 +146,10 @@ Sema::ExprResult Sema::ActOnClassMessage( ObjCInterfaceDecl* ClassDecl = 0; if (!strcmp(receiverName->getName(), "super") && CurMethodDecl) { ClassDecl = CurMethodDecl->getClassInterface()->getSuperClass(); - if (ClassDecl && CurMethodDecl->isInstance()) { + if (!ClassDecl) + return Diag(lbrac, diag::error_no_super_class, + CurMethodDecl->getClassInterface()->getName()); + if (CurMethodDecl->isInstance()) { // Synthesize a cast to the super class. This hack allows us to loosely // represent super without creating a special expression node. IdentifierInfo &II = Context.Idents.get("self"); diff --git a/test/Sema/undef-superclass-1.m b/test/Sema/undef-superclass-1.m index 822b97185b..7e12463654 100644 --- a/test/Sema/undef-superclass-1.m +++ b/test/Sema/undef-superclass-1.m @@ -18,3 +18,9 @@ @interface INTF1 // expected-error {{duplicate interface declaration for class 'INTF1'}} @end + +@implementation SUPER +- (void)dealloc { + [super dealloc]; // expected-error {{no super class declared in @interface for 'SUPER'}} +} +@end -- 2.40.0