mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 08:06:40 +00:00
[clang-format] Hanlde qualified type name for QualifierAlignment
(#125327)
Fixes #125178.
This commit is contained in:
parent
cdca04913a
commit
eb6ca1242c
@ -132,8 +132,10 @@ static void rotateTokens(const SourceManager &SourceMgr,
|
||||
// Then move through the other tokens.
|
||||
auto *Tok = Begin;
|
||||
while (Tok != End) {
|
||||
if (!NewText.empty() && !endsWithSpace(NewText))
|
||||
if (!NewText.empty() && !endsWithSpace(NewText) &&
|
||||
Tok->isNot(tok::coloncolon)) {
|
||||
NewText += " ";
|
||||
}
|
||||
|
||||
NewText += Tok->TokenText;
|
||||
Tok = Tok->Next;
|
||||
@ -412,6 +414,14 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
|
||||
// The case `const long long volatile int` -> `const volatile long long int`
|
||||
// The case `long volatile long int const` -> `const volatile long long int`
|
||||
if (TypeToken->isTypeName(LangOpts)) {
|
||||
for (const auto *Prev = TypeToken->Previous;
|
||||
Prev && Prev->is(tok::coloncolon); Prev = Prev->Previous) {
|
||||
TypeToken = Prev;
|
||||
Prev = Prev->Previous;
|
||||
if (!(Prev && Prev->is(tok::identifier)))
|
||||
break;
|
||||
TypeToken = Prev;
|
||||
}
|
||||
const FormatToken *LastSimpleTypeSpecifier = TypeToken;
|
||||
while (isConfiguredQualifierOrType(
|
||||
LastSimpleTypeSpecifier->getPreviousNonComment(),
|
||||
|
@ -1291,6 +1291,21 @@ TEST_F(QualifierFixerTest, WithCpp11Attribute) {
|
||||
"[[maybe_unused]] constexpr static int A", Style);
|
||||
}
|
||||
|
||||
TEST_F(QualifierFixerTest, WithQualifiedTypeName) {
|
||||
auto Style = getLLVMStyle();
|
||||
Style.QualifierAlignment = FormatStyle::QAS_Custom;
|
||||
Style.QualifierOrder = {"constexpr", "type", "const"};
|
||||
|
||||
verifyFormat("constexpr ::int64_t x{1};", "::int64_t constexpr x{1};", Style);
|
||||
verifyFormat("constexpr std::int64_t x{123};",
|
||||
"std::int64_t constexpr x{123};", Style);
|
||||
verifyFormat("constexpr ::std::int64_t x{123};",
|
||||
"::std::int64_t constexpr x{123};", Style);
|
||||
|
||||
Style.TypeNames.push_back("bar");
|
||||
verifyFormat("constexpr foo::bar x{12};", "foo::bar constexpr x{12};", Style);
|
||||
}
|
||||
|
||||
TEST_F(QualifierFixerTest, DisableRegions) {
|
||||
FormatStyle Style = getLLVMStyle();
|
||||
Style.QualifierAlignment = FormatStyle::QAS_Custom;
|
||||
|
Loading…
x
Reference in New Issue
Block a user