[cfe-commits] r71817 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/class-conforming-protocol-2.m test/SemaObjC/method-conflict.m

Daniel Dunbar daniel at zuster.org
Fri May 15 19:35:55 PDT 2009


Fariborz,

Is there code which motivates this? I can understand this for return
types but doing this for argument types seems actively wrong, the body
of the method will be allowed to call messages defined in the sub
protocol without error, even though clients can call it without
warning with an object which does not (claim to) implement those
methods.

I understand that this things aren't very well defined, but I think we
should make an attempt to handle covariance/contravariance of
qualified id types correctly if at all possible.

 - Daniel

On Thu, May 14, 2009 at 4:53 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Thu May 14 18:52:54 2009
> New Revision: 71817
>
> URL: http://llvm.org/viewvc/llvm-project?rev=71817&view=rev
> Log:
> Don't warn if result/argument type of an implemented
> method is a qualified id which conforms to the matching type
> of its method declaration.
>
> Added:
>    cfe/trunk/test/SemaObjC/class-conforming-protocol-2.m
> Modified:
>    cfe/trunk/lib/Sema/Sema.h
>    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
>    cfe/trunk/lib/Sema/SemaExprObjC.cpp
>    cfe/trunk/test/SemaObjC/method-conflict.m
>
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=71817&r1=71816&r2=71817&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Thu May 14 18:52:54 2009
> @@ -1082,6 +1082,7 @@
>                            bool &IncompleteImpl);
>   void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
>                                    ObjCMethodDecl *IntfMethod);
> +  bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
>
>   NamespaceDecl *GetStdNamespace();
>
>
> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=71817&r1=71816&r2=71817&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu May 14 18:52:54 2009
> @@ -775,7 +775,9 @@
>  void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
>                                        ObjCMethodDecl *IntfMethodDecl) {
>   if (!Context.typesAreCompatible(IntfMethodDecl->getResultType(),
> -                                  ImpMethodDecl->getResultType())) {
> +                                  ImpMethodDecl->getResultType()) &&
> +      !QualifiedIdConformsQualifiedId(IntfMethodDecl->getResultType(),
> +                                      ImpMethodDecl->getResultType())) {
>     Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types)
>       << ImpMethodDecl->getDeclName() << IntfMethodDecl->getResultType()
>       << ImpMethodDecl->getResultType();
> @@ -785,7 +787,8 @@
>   for (ObjCMethodDecl::param_iterator IM = ImpMethodDecl->param_begin(),
>        IF = IntfMethodDecl->param_begin(), EM = ImpMethodDecl->param_end();
>        IM != EM; ++IM, ++IF) {
> -    if (Context.typesAreCompatible((*IF)->getType(), (*IM)->getType()))
> +    if (Context.typesAreCompatible((*IF)->getType(), (*IM)->getType()) ||
> +        QualifiedIdConformsQualifiedId((*IF)->getType(), (*IM)->getType()))
>       continue;
>
>     Diag((*IM)->getLocation(), diag::warn_conflicting_param_types)
>
> Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=71817&r1=71816&r2=71817&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu May 14 18:52:54 2009
> @@ -697,6 +697,15 @@
>   return false;
>  }
>
> +/// QualifiedIdConformsQualifiedId - compare id<p,...> with id<p1,...>
> +/// return true if lhs's protocols conform to rhs's protocol; false
> +/// otherwise.
> +bool Sema::QualifiedIdConformsQualifiedId(QualType lhs, QualType rhs) {
> +  if (lhs->isObjCQualifiedIdType() && rhs->isObjCQualifiedIdType())
> +    return ObjCQualifiedIdTypesAreCompatible(lhs, rhs, false);
> +  return false;
> +}
> +
>  /// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an
>  /// ObjCQualifiedIDType.
>  /// FIXME: Move to ASTContext::typesAreCompatible() and friends.
>
> Added: cfe/trunk/test/SemaObjC/class-conforming-protocol-2.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-conforming-protocol-2.m?rev=71817&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/class-conforming-protocol-2.m (added)
> +++ cfe/trunk/test/SemaObjC/class-conforming-protocol-2.m Thu May 14 18:52:54 2009
> @@ -0,0 +1,22 @@
> +// RUN: clang-cc  -fsyntax-only -verify %s
> +
> + at protocol NSWindowDelegate @end
> +
> + at interface NSWindow
> +- (void)setDelegate:(id <NSWindowDelegate>)anObject;
> +- (id <NSWindowDelegate>) delegate;
> + at end
> +
> + at protocol IBStringsTableWindowDelegate <NSWindowDelegate>
> + at end
> +
> + at interface IBStringsTableWindow : NSWindow {}
> + at end
> +
> + at implementation IBStringsTableWindow
> +- (void)setDelegate:(id <IBStringsTableWindowDelegate>)delegate {
> +}
> +- (id <IBStringsTableWindowDelegate>)delegate {
> +        return 0;
> +}
> + at end
>
> Modified: cfe/trunk/test/SemaObjC/method-conflict.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-conflict.m?rev=71817&r1=71816&r2=71817&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/method-conflict.m (original)
> +++ cfe/trunk/test/SemaObjC/method-conflict.m Thu May 14 18:52:54 2009
> @@ -40,7 +40,7 @@
>  @end  @class XDSCOperation;
>  @interface XDSCClassFormatter : NSObject {
>  }
> -+ (NSUInteger) compartmentsForClassifier: (id <XDUMLClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec; // expected-note {{previous definition is here}}
> ++ (NSUInteger) compartmentsForClassifier: (id <XDUMLClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec;
>  @end
>  @class NSString;
>  @implementation XDSCClassFormatter
> @@ -48,7 +48,6 @@
>  + appendVisibility: (id <XDUMLNamedElement>) element withSpecification: (XDSCDisplaySpecification *) displaySpec to: (NSMutableAttributedString *) attributedString
>  {
>  }
> -// GCC doesn't currently warn about this.
> -+ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec { // expected-warning {{conflicting parameter types in implementation of 'compartmentsForClassifier:withSpecification:': 'id<XDUMLClassifier>' vs 'id<XDSCClassifier>'}}
> ++ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec {
>  }
>  @end
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list