[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
Wed Jan 15 06:46:46 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:

Github is making this not great here... but why is the check for the LParen here, and how is it working?  Some of the attributes I'd think we'd ONLY want to diagnose if it is a function type.  That is, a macro:

`#define assume baz`

Should be fine.

But
`#define assume() baz`

is not.

`deprecated` as well should warn either way (since it is allowed to have an argument), same with `no_discard`.

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


More information about the llvm-commits mailing list