[cfe-commits] r92488 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/undef-superclass-1.m
Douglas Gregor
dgregor at apple.com
Mon Jan 4 09:27:13 PST 2010
Author: dgregor
Date: Mon Jan 4 11:27:12 2010
New Revision: 92488
URL: http://llvm.org/viewvc/llvm-project?rev=92488&view=rev
Log:
When declaring an Objective-C implementation without a corresponding
interface, suggest correction of typos. For example, given:
@interface NSString
@end
@implementation NSstring
@end
we'll warn with:
t.m:4:19: warning: cannot find interface declaration for 'NSstring';
did you mean 'NSString'?
@implementation NSstring
^
However, since this is just a warning, we don't provide a fix-it
hint. Good idea, Ted!
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/undef-superclass-1.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=92488&r1=92487&r2=92488&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 4 11:27:12 2010
@@ -2575,6 +2575,8 @@
"property %0 not found on object of type %1; did you mean %2?">;
def err_undef_interface_suggest : Error<
"cannot find interface declaration for %0; did you mean %1?">;
+def warn_undef_interface_suggest : Warning<
+ "cannot find interface declaration for %0; did you mean %1?">;
def err_undef_superclass_suggest : Error<
"cannot find interface declaration for %0, superclass of %1; did you mean "
"%2?">;
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=92488&r1=92487&r2=92488&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Jan 4 11:27:12 2010
@@ -689,13 +689,27 @@
if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
- } else {
- // Is there an interface declaration of this class; if not, warn!
- IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
- if (!IDecl || IDecl->isForwardDecl()) {
+ } else if ((IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))) {
+ // If this is a forward declaration of an interface, warn.
+ if (IDecl->isForwardDecl()) {
Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
IDecl = 0;
}
+ } else {
+ // We did not find anything with the name ClassName; try to correct for
+ // typos in the class name.
+ LookupResult R(*this, ClassName, ClassLoc, LookupOrdinaryName);
+ if (CorrectTypo(R, TUScope, 0) &&
+ (IDecl = R.getAsSingle<ObjCInterfaceDecl>())) {
+ // Suggest the (potentially) correct interface name. However, don't
+ // provide a code-modification hint or use the typo name for recovery,
+ // because this is just a warning. The program may actually be correct.
+ Diag(ClassLoc, diag::warn_undef_interface_suggest)
+ << ClassName << R.getLookupName();
+ IDecl = 0;
+ } else {
+ Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
+ }
}
// Check that super class name is valid class name
Modified: cfe/trunk/test/SemaObjC/undef-superclass-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/undef-superclass-1.m?rev=92488&r1=92487&r2=92488&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/undef-superclass-1.m (original)
+++ cfe/trunk/test/SemaObjC/undef-superclass-1.m Mon Jan 4 11:27:12 2010
@@ -31,3 +31,5 @@
@implementation RecursiveClass
@end
+ at implementation iNTF3 // expected-warning{{cannot find interface declaration for 'iNTF3'; did you mean 'INTF3'?}}
+ at end
More information about the cfe-commits
mailing list