[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:11:49 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";
----------------
hokein wrote:

> Why are we not using %select for that?

Can you explain a bit more? IIUC, you're suggesting using the `err_attribute_wrong_decl_type` the one with the "%select"? That is possible, but then we'll need to add a new Kind in `AttributeDeclKind`.

> Beside, is "implicit object parameters" sufficiently understandable? - or should we say "member functions"?

I think the implicit object parameter is fine. "member functions" is not entirely correct, the attribute is on the implicit object parameter even though it is applied to a function type in the implementation.

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


More information about the cfe-commits mailing list