[PATCH] D42464: add prefix with '_' support for property name. Corresponding apple dev doc: https://developer.apple.com/library/content/qa/qa1908/_index.html

Yan Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 29 14:32:33 PST 2018


Wizard marked 3 inline comments as done.
Wizard added inline comments.


================
Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:151
+      hasCategoryPropertyPrefix(MatchedDecl->getName())) {
+    const auto *CategoryDecl = (const ObjCCategoryDecl *)(DeclContext);
+    if (!prefixedPropertyNameMatches(MatchedDecl->getName(), SpecialAcronyms) ||
----------------
benhamilton wrote:
> Wizard wrote:
> > hokein wrote:
> > > Wizard wrote:
> > > > hokein wrote:
> > > > > Consider using `const auto* CategoryDecl = dyn_cast<ObjCCategoryDecl*>(DeclContext)`, we can get rid of this cast, and `NodeKind` variable.
> > > > Tried that before but I encountered 2 issues:
> > > > 1. 'clang::DeclContext' is not polymorphic
> > > > 2. cannot use dynamic_cast with -fno-rtti
> > > > which are preventing me from using dynamic_cast
> > > Sorry, I mean `llvm::dyn_cast` here, it should work.
> > It is not working either. It says "error: static_cast from 'clang::Decl *' to 'const clang::ObjCCategoryDecl *const *' is not allowed" though I have no idea why it is regarded as a static cast.
> > I am using it like this:
> > const auto *CategoryDecl = llvm::dyn_cast<const ObjCCategoryDecl *>(DeclContext);
> You definitely don't want to use a C-style cast. My guess is adding const is not part of what dyn_cast<> does, so you can probably remove that from the dyn_cast<>. (You can of course assign to a const pointer if you want.)
> 
Finally figured out that I cannot put pointer type in dyn_cast<>. It needs to be "llvm::dyn_cast<ObjCCategoryDecl>(DeclContext)" even though DeclContext is a pointer. I have to say it is weird in C++...


================
Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:163
+            MatchedDecl->getName(),
+            llvm::ArrayRef<std::string>(SpecialAcronyms)) ||
+        CategoryDecl->IsClassExtension()) {
----------------
hokein wrote:
> Do we need it? I think you can pass `SpecialAcronyms` directly.
It is not about acronyms but determine how to generate the fix. It will save me from checking the naming format again when generating the fix hint.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42464





More information about the cfe-commits mailing list