Skip to content

[clang-format] Handle leading C++11 attribute in QualifierAlignment #123690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/Format/QualifierAlignmentFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
// For left qualifiers preceeded by nothing, a template declaration, or *,&,&&
// we only perform sorting.
if (!TypeToken || TypeToken->isPointerOrReference() ||
TypeToken->ClosesRequiresClause || TypeToken->ClosesTemplateDeclaration) {
TypeToken->ClosesRequiresClause || TypeToken->ClosesTemplateDeclaration ||
TypeToken->is(tok::r_square)) {

// Don't sort past a non-configured qualifier token.
const FormatToken *FirstQual = Tok;
Expand Down
12 changes: 12 additions & 0 deletions clang/unittests/Format/QualifierFixerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,18 @@ TEST_F(QualifierFixerTest, WithConstraints) {
Style);
}

TEST_F(QualifierFixerTest, WithCpp11Attribute) {
FormatStyle Style = getLLVMStyle();
Style.QualifierAlignment = FormatStyle::QAS_Custom;
Style.QualifierOrder = {"static", "constexpr", "inline", "type"};

verifyFormat("[[nodiscard]] static constexpr inline int func() noexcept {}",
"[[nodiscard]] inline constexpr static int func() noexcept {}",
Style);
verifyFormat("[[maybe_unused]] static constexpr int A",
"[[maybe_unused]] constexpr static int A", Style);
}

TEST_F(QualifierFixerTest, DisableRegions) {
FormatStyle Style = getLLVMStyle();
Style.QualifierAlignment = FormatStyle::QAS_Custom;
Expand Down
Loading