Author: camc Date: 2025-09-15T21:04:45+08:00 New Revision: e0a33cb599f8614b3d897ad2bd2f9fa8e1acbac5
URL: https://github.com/llvm/llvm-project/commit/e0a33cb599f8614b3d897ad2bd2f9fa8e1acbac5 DIFF: https://github.com/llvm/llvm-project/commit/e0a33cb599f8614b3d897ad2bd2f9fa8e1acbac5.diff LOG: [clang] Allow attributes on first constructor argument in pre-C++11 (#157300) Resolves GH-156809 Modifies decl parser to allow C++11 style [[attributes]] on the first argument in constructors in all C++ standards. They are already allowed on later arguments. --------- Co-authored-by: Shafik Yaghmour <shafik.yaghm...@intel.com> Added: clang/test/Parser/cxx03-attributes.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Parse/ParseDecl.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index bdf8334f78cea..dbba8f5db0cef 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -365,6 +365,8 @@ Bug Fixes to C++ Support authentication enabled. (#GH152601) - Fix the check for narrowing int-to-float conversions, so that they are detected in cases where converting the float back to an integer is undefined behaviour (#GH157067). +- Stop rejecting C++11-style attributes on the first argument of constructors in older + standards. (#GH156809). - Fix a crash when applying binary or ternary operators to two same function types with diff erent spellings, where at least one of the function parameters has an attribute which affects the function type. diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 10355bb874762..bbeee2e3e373f 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -6007,10 +6007,9 @@ bool Parser::isConstructorDeclarator(bool IsUnqualified, bool DeductionGuide, // A C++11 attribute here signals that we have a constructor, and is an // attribute on the first constructor parameter. - if (getLangOpts().CPlusPlus11 && - isCXX11AttributeSpecifier(/*Disambiguate*/ false, - /*OuterMightBeMessageSend*/ true) != - CXX11AttributeKind::NotAttributeSpecifier) { + if (isCXX11AttributeSpecifier(/*Disambiguate=*/false, + /*OuterMightBeMessageSend=*/true) != + CXX11AttributeKind::NotAttributeSpecifier) { return true; } diff --git a/clang/test/Parser/cxx03-attributes.cpp b/clang/test/Parser/cxx03-attributes.cpp new file mode 100644 index 0000000000000..d3afef76366a3 --- /dev/null +++ b/clang/test/Parser/cxx03-attributes.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++03 %s +// expected-no-diagnostics + +struct S { + S([[clang::lifetimebound]] int&) {} +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits