From e2573e529d8630e1586e8fb1230938d6e1d799e5 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 6 Apr 2009 23:43:32 +0000 Subject: [PATCH] Warn instead of error on duplicate protocol definitions. Be kind to so many projects which are doing this (and be like gcc). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68474 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 +- lib/Sema/SemaDeclObjC.cpp | 3 +-- test/SemaObjC/check-dup-objc-decls-1.m | 2 +- test/SemaObjC/protocol-test-2.m | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b51162ae94..ddb066e3d6 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -128,7 +128,7 @@ def err_undef_superclass : Error< def warn_previous_alias_decl : Warning<"previously declared alias is ignored">; def err_conflicting_aliasing_type : Error<"conflicting types for alias %0">; def warn_undef_interface : Warning<"cannot find interface declaration for %0">; -def err_duplicate_protocol_def : Error<"duplicate protocol definition of %0">; +def warn_duplicate_protocol_def : Warning<"duplicate protocol definition of %0 is ignored">; def err_protocol_has_circular_dependency : Error< "protocol has circular dependency">; def err_undeclared_protocol : Error<"cannot find protocol declaration for %0">; diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 0103393ddc..17de0a5067 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -246,8 +246,7 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc, if (PDecl) { // Protocol already seen. Better be a forward protocol declaration if (!PDecl->isForwardDecl()) { - PDecl->setInvalidDecl(); - Diag(ProtocolLoc, diag::err_duplicate_protocol_def) << ProtocolName; + Diag(ProtocolLoc, diag::warn_duplicate_protocol_def) << ProtocolName; Diag(PDecl->getLocation(), diag::note_previous_definition); // Just return the protocol we already had. // FIXME: don't leak the objects passed in! diff --git a/test/SemaObjC/check-dup-objc-decls-1.m b/test/SemaObjC/check-dup-objc-decls-1.m index 4181ac097b..dc9c8f4426 100644 --- a/test/SemaObjC/check-dup-objc-decls-1.m +++ b/test/SemaObjC/check-dup-objc-decls-1.m @@ -33,7 +33,7 @@ void Gorf() // expected-error {{redefinition of 'Gorf' as different kind of symb @interface A @end // expected-error {{duplicate interface definition for class 'A'}} @protocol PP

@end // expected-note {{previous definition is here}} -@protocol PP @end // expected-error {{duplicate protocol definition of 'PP'}} +@protocol PP @end // expected-warning {{duplicate protocol definition of 'PP'}} @interface A(Cat)

@end // expected-note {{previous definition is here}} @interface A(Cat) @end // expected-warning {{duplicate definition of category 'Cat' on interface 'A'}} diff --git a/test/SemaObjC/protocol-test-2.m b/test/SemaObjC/protocol-test-2.m index a882809f1c..3abb9b5935 100644 --- a/test/SemaObjC/protocol-test-2.m +++ b/test/SemaObjC/protocol-test-2.m @@ -18,7 +18,7 @@ @protocol PROTO // expected-note {{previous definition is here}} @end -@protocol PROTO // expected-error {{duplicate protocol definition of 'PROTO'}} +@protocol PROTO // expected-warning {{duplicate protocol definition of 'PROTO'}} @end @protocol PROTO3 -- 2.50.1