[PATCH] D28166: Properly merge K&R functions that have attributes

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 29 14:56:09 PST 2016


aaron.ballman added inline comments.


================
Comment at: lib/Sema/SemaDecl.cpp:7464-7470
+    const Type *NonAttributedFTy = R.getTypePtr();
+    while (const auto *AttrTy = NonAttributedFTy->getAs<AttributedType>()) {
+      NonAttributedFTy = AttrTy->getModifiedType().getTypePtr();
+    }
     bool HasPrototype =
       (D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) ||
+      (!isa<FunctionType>(NonAttributedFTy) && R->isFunctionProtoType());
----------------
rsmith wrote:
> Rather than hardcoding the forms of type sugar that can appear here, can we just use `R.getTypePtr()->getAs<FunctionType>()`? I expect we can also have `ParenType`s wrapping the `FunctionNoProtoType` (`int (f)();`).
Good point about `ParenType`, but no, you cannot use `R->getAs<FunctionType>()`, because that strips off all sugar, including typedefs. However, I share your concern about hardcoding the forms of sugar. Perhaps we should add `getAsAdjusted<T>()` like you were suggesting for `TypeLoc` to `Type` as well?


https://reviews.llvm.org/D28166





More information about the cfe-commits mailing list