[clang] [clang] Informative error for lifetimebound in decl-spec (PR #118567)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 5 01:15:29 PST 2024


================
@@ -3703,8 +3703,14 @@ void Parser::ParseDeclarationSpecifiers(
           // We reject AT_LifetimeBound and AT_AnyX86NoCfCheck, even though they
           // are type attributes, because we historically haven't allowed these
           // to be used as type attributes in C++11 / C23 syntax.
-          if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
-              PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
+          if (PA.getKind() == ParsedAttr::AT_LifetimeBound) {
+            Diag(PA.getLoc(), diag::err_attribute_wrong_decl_type_str)
+                << PA << PA.isRegularKeywordAttribute()
+                << "parameters and implicit object parameters";
+            PA.setInvalid();
+            continue;
+          }
+          if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
----------------
hokein wrote:

nit: I think restructuring the code like following is easier to understand

```
if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
              PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
   continue;

if (PA.getKind() == ParsedAttr::AT_LifetimeBound) {
    Diag(PA.getLoc(), diag::err_attribute_wrong_decl_type_str)
                << PA << PA.isRegularKeywordAttribute()
                << "parameters and implicit object parameters";
else
    Diag(PA.getLoc(), diag::err_attribute_not_type_attr)
              << PA << PA.isRegularKeywordAttribute();
PA.setInvalid();
```

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


More information about the cfe-commits mailing list