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

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 1 15:18:09 PDT 2024


================
@@ -177,6 +177,26 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
   return false;
 }
 
+static bool isReservedAttrName(Preprocessor &PP, IdentifierInfo *II) {
----------------
a-tarasyuk wrote:

The reason I asked is that I recall clang has a predefined macro, `__has_cpp_attribute`, which relies on `hasAttribute`. This function uses a list of existing attributes generated from `Attr.td` for different _`Syntax`_. Should attributes currently defined in clang (for example, `indeterminate` isn’t defined yet) be disallowed, or should all cpp attribute names from the standard be considered?

--- 

https://github.com/llvm/llvm-project/blob/357bd61744bb8cc2b9b07447294fa977e5758550/clang/lib/Lex/PPMacroExpansion.cpp#L1915-L1920

https://github.com/llvm/llvm-project/blob/357bd61744bb8cc2b9b07447294fa977e5758550/clang/lib/Basic/Attributes.cpp#L31

https://github.com/llvm/llvm-project/blob/357bd61744bb8cc2b9b07447294fa977e5758550/clang/lib/Basic/Attributes.cpp#L26

```
...
if (ScopeName == "") {
  return llvm::StringSwitch<int>(Name)
    .Case("noreturn", 200809)
    .Case("assume", 202207)
    .Case("carries_dependency", 200809)
    .Case("deprecated", 201309)
    .Case("fallthrough", 201603)
    .Case("likely", 201803)
    .Case("no_unique_address", true && ( Target.getCXXABI().isItaniumFamily() ) ? 201803 : 0)
    .Case("unlikely", 201803)
    .Case("maybe_unused", 201603)
    .Case("nodiscard", 201907)
    .Default(0);
...
```

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


More information about the cfe-commits mailing list