[PATCH] D89212: PR47663: Warn if an entity becomes weak after its first use.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 19 07:05:59 PDT 2020


aaron.ballman added inline comments.


================
Comment at: clang/lib/Sema/SemaDecl.cpp:6435-6436
+    Attr *WeakA = nullptr;
+    for (Attr *A : VD->getAttrs()) {
+      if (!isa<WeakAttr, WeakRefAttr, WeakImportAttr, AvailabilityAttr>(A))
+        continue;
----------------
rsmith wrote:
> aaron.ballman wrote:
> > Ah, it's too bad that `Decl::specific_attrs()` doesn't accept a pack of attributes...
> I took a brief look at fixing that, but it's not a completely natural extension because we would want to use a different `value_type` for the iterator if there's more than one kind under consideration. Probably not worth it for only one user.
Agreed, thank you for looking into it!


================
Comment at: clang/lib/Sema/SemaDecl.cpp:18288
 
-  if (PrevDecl) {
-    PrevDecl->addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc, AttributeCommonInfo::AS_Pragma));
+  if (NamedDecl *PrevDecl =
+          LookupSingleName(TUScope, Name, NameLoc, LookupOrdinaryName)) {
----------------
rsmith wrote:
> aaron.ballman wrote:
> > Same request for `const` here as above.
> Can't make this `const`; this function modifies the declaration by adding an attribute :) But I can make `VD` below const.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89212



More information about the cfe-commits mailing list