[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 19:55:44 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 _(maybe `hasAttribute` could be reused)_, or should all cpp attribute names from the standard be considered _(even if Clang doesn’t fully support it)_?

--- 

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);
...
```

--- 

Should this one handle the standard versions too?
https://github.com/llvm/llvm-project/blob/837ee5b46a5f7f898f0de7e46a19600b896a0a1f/clang/lib/Parse/ParseDeclCXX.cpp#L4689-L4708

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


More information about the cfe-commits mailing list