[PATCH] D63954: Add lifetime categories attributes

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 14:20:41 PDT 2019


erik.pilkington added a comment.

> We explicitly allow to add an annotation after
>  the definition of the class to allow adding annotations
>  to external source from by the user, e.g.
> 
>   #include <vector>
>   
>   namespace std {
>   template<typename T, typename Alloc>
>   class [[gsl::Owner(T)]] vector;
>   }

Wait, does that even work? What if the vector was declared in an inline namespace in the header? Seems like a strange recommendation for users. Is there some reason you can't just add these annotations to standard libraries? I doubt libcxx would have a problem with getting better warnings on their types.



================
Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4560-4561
+  if(AL.getKind() ==  ParsedAttr::AT_Owner) {
+    if (checkAttrMutualExclusion<PointerAttr>(S, D, AL))
+      return;
+    if (const auto *Attr = D->getAttr<OwnerAttr>()) {
----------------
This is duplicated with the first line in the function.


================
Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4564
+      if (Attr->getDerefType().getTypePtr() != ParmType.getTypePtr()) {
+        S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << Attr;
+        S.Diag(Attr->getLocation(), diag::note_conflicting_attribute);
----------------
`diag::warn_duplicate_attr`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63954





More information about the cfe-commits mailing list