[PATCH] D124285: [clang][NFC] In parts of Objective-C Sema use Obj-C-specific types instead of `Decl`.

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 28 02:10:39 PDT 2022


jansvoboda11 added inline comments.


================
Comment at: clang/include/clang/Sema/Sema.h:3300
 
-  Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
+  void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl);
 
----------------
vsapsai wrote:
> jansvoboda11 wrote:
> > Why the change in return type?
> Initially I've changed the type to catch various `return ActOnObjCContainerStartDefinition..` Now it's not really required.
> 
> What type do you think it should be? We can do both `Decl *` and `ObjCContainerDecl *` though none of those is particularly useful. I've decided to keep `void` because we don't use the returned value anyway.
> 
> I was also considering
> ```lang=c++
> template <typename ObjCDeclTy>
> ObjCDeclTy *ActOnObjCContainerStartDefinition(ObjCDeclTy *IDecl);
> ```
> 
> but I feel like the introduced complexity isn't worth it.
I see. I'm fine with having `void` here, what caught my attention was changing `return ActOnObjCContainerStartDefinition(X);` into `ActOnObjCContainerStartDefinition(X); return X;` that's perfectly fine though.


================
Comment at: clang/lib/Sema/SemaDecl.cpp:17067
+void Sema::ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx) {
+  auto DC = cast<DeclContext>(ObjCCtx);
   assert(DC == CurContext && "Mismatch of container contexts");
----------------
vsapsai wrote:
> jansvoboda11 wrote:
> > Why the cast? We should be able to compare/assign `ObjCContainerDecl *` to `DeclContext *`.
> I believe you are right and the cast is not required. Though we cannot compare `ObjCCtx` and `CurContext`, we need to compare `DeclContext *DC`.
> 
> Also dropped a similar cast in `ActOnObjCContainerStartDefinition`.
Interesting, I would expect that `ObjCCtx == CurContext` would have implicit upcast of `ObjCCtx` to `DeclContext *`. Same for the assignment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124285/new/

https://reviews.llvm.org/D124285



More information about the cfe-commits mailing list