diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 937a94b02458c..7f3f6d568e28c 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3706,8 +3706,14 @@ void Parser::ParseDeclarationSpecifiers( if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound && PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck) continue; - Diag(PA.getLoc(), diag::err_attribute_not_type_attr) - << PA << PA.isRegularKeywordAttribute(); + + 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(); } diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp b/clang/test/SemaCXX/attr-lifetimebound.cpp index c7abec61873ef..896793f996666 100644 --- a/clang/test/SemaCXX/attr-lifetimebound.cpp +++ b/clang/test/SemaCXX/attr-lifetimebound.cpp @@ -10,7 +10,7 @@ namespace usage_invalid { static int *static_class_member() [[clang::lifetimebound]]; // expected-error {{static member function has no implicit object parameter}} int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error {{explicit object member function has no implicit object parameter}} int attr_on_var [[clang::lifetimebound]]; // expected-error {{only applies to parameters and implicit object parameters}} - int [[clang::lifetimebound]] attr_on_int; // expected-error {{cannot be applied to types}} + int [[clang::lifetimebound]] attr_on_int; // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}} int * [[clang::lifetimebound]] attr_on_int_ptr; // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}} int * [[clang::lifetimebound]] * attr_on_int_ptr_ptr; // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}} int (* [[clang::lifetimebound]] attr_on_func_ptr)(); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}} @@ -19,7 +19,7 @@ namespace usage_invalid { int *attr_with_param(int ¶m [[clang::lifetimebound(42)]]); // expected-error {{takes no arguments}} void attr_on_ptr_arg(int * [[clang::lifetimebound]] ptr); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}} - static_assert((int [[clang::lifetimebound]]) 12); // expected-error {{cannot be applied to types}} + static_assert((int [[clang::lifetimebound]]) 12); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}} int* attr_on_unnamed_arg(const int& [[clang::lifetimebound]]); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}} template int* attr_on_template_ptr_arg(T * [[clang::lifetimebound]] ptr); // expected-error {{'lifetimebound' attribute only applies to parameters and implicit object parameters}}