mizvekov added a comment.

@kimgr One other general comment.

The way this function is implemented is quite error prone:

  static const NamedDecl* TypeToDeclImpl(const Type* type, bool as_written) {
    // Get past all the 'class' and 'struct' prefixes, and namespaces.
    type = RemoveElaboration(type);
  
    // Read past SubstTemplateTypeParmType (this can happen if a
    // template function returns the tpl-arg type: e.g. for
    // 'T MyFn<T>() {...}; MyFn<X>.a', the type of MyFn<X> will be a Subst.
    type = RemoveSubstTemplateTypeParm(type);
  
    CHECK_(!isa<ObjCObjectType>(type) && "IWYU doesn't support Objective-C");

Ie the beginning is being too explicit, testing for very specific sugar type 
nodes kinds, in a very specific order, just to skip over them.

That makes it very fragile against clang changes.

You can instead just use `getAs` to step over them in a generic fashion.

I don't think this one gets broken by this MR, but I am very confident it will 
get broken by another patch I have.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112374

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to