[clang] [llvm] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)

Erich Keane via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 06:32:35 PST 2025


================
@@ -173,6 +176,20 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
   return false;
 }
 
+static bool isReservedCXXAttributeName(Preprocessor &PP, IdentifierInfo *II) {
+  const LangOptions &Lang = PP.getLangOpts();
+  if (Lang.CPlusPlus &&
+      hasAttribute(AttributeCommonInfo::Syntax::AS_CXX11, /*Scope*/ nullptr, II,
+                   PP.getTargetInfo(), Lang) > 0) {
+    AttributeCommonInfo::Kind AttrKind = AttributeCommonInfo::getParsedKind(
+        II, /*Scope*/ nullptr, AttributeCommonInfo::Syntax::AS_CXX11);
+    return !((AttrKind == AttributeCommonInfo::Kind::AT_Likely ||
+              AttrKind == AttributeCommonInfo::Kind::AT_Unlikely) &&
+             PP.isNextPPTokenLParen());
----------------
erichkeane wrote:

I think all the behavior about the function-likeness is exactly what I was hoping for/asking for.  I don't LOVE using `hasAttributeImpl` for anything other than the implementation of `hasAttribute`?  But perhaps the perf is worth it


https://github.com/llvm/llvm-project/pull/106036


More information about the llvm-commits mailing list