[PATCH] D76704: Don't normalise CXX11/C2X attribute names to start with ::

John Brawn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 24 07:30:01 PDT 2020


john.brawn created this revision.
john.brawn added reviewers: erichkeane, aaron.ballman, rjmccall.
Herald added a project: clang.
john.brawn added a child revision: D31343: Add an attribute plugin example.

Currently square-bracket-style (CXX11/C2X) attribute names are normalised to start with :: if they don't have a namespace. This is a bit odd, as such names are rejected when parsing, so don't do this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76704

Files:
  clang/lib/Basic/Attributes.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===================================================================
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3739,10 +3739,8 @@
     for (const auto &S : GetFlattenedSpellings(Attr)) {
       const std::string &RawSpelling = S.name();
       std::string Spelling;
-      if (S.variety() == "CXX11" || S.variety() == "C2x") {
-        Spelling += S.nameSpace();
-        Spelling += "::";
-      }
+      if (!S.nameSpace().empty())
+        Spelling += S.nameSpace() + "::";
       if (S.variety() == "GNU")
         Spelling += NormalizeGNUAttrSpelling(RawSpelling);
       else
@@ -3815,12 +3813,12 @@
         const std::string &Variety = S.variety();
         if (Variety == "CXX11") {
           Matches = &CXX11;
-          Spelling += S.nameSpace();
-          Spelling += "::";
+          if (!S.nameSpace().empty())
+            Spelling += S.nameSpace() + "::";
         } else if (Variety == "C2x") {
           Matches = &C2x;
-          Spelling += S.nameSpace();
-          Spelling += "::";
+          if (!S.nameSpace().empty())
+            Spelling += S.nameSpace() + "::";
         } else if (Variety == "GNU")
           Matches = &GNU;
         else if (Variety == "Declspec")
Index: clang/lib/Basic/Attributes.cpp
===================================================================
--- clang/lib/Basic/Attributes.cpp
+++ clang/lib/Basic/Attributes.cpp
@@ -85,11 +85,8 @@
   StringRef ScopeName = normalizeAttrScopeName(Scope, SyntaxUsed);
   StringRef AttrName = normalizeAttrName(Name, ScopeName, SyntaxUsed);
 
-  // Ensure that in the case of C++11 attributes, we look for '::foo' if it is
-  // unscoped.
   SmallString<64> FullName = ScopeName;
-  if (Scope || SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
-      SyntaxUsed == AttributeCommonInfo::AS_C2x)
+  if (!ScopeName.empty())
     FullName += "::";
   FullName += AttrName;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76704.252308.patch
Type: text/x-patch
Size: 1966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200324/6ac59b64/attachment.bin>


More information about the cfe-commits mailing list