llvm / llvm/llvm-project

`clang-format`sorts or groups namespaces in using declarations in a case-insensitive way

Open
#182,323 1 comment 0 reactions 0 assignees View on GitHub
clang-format
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`clang-format` seems to treat the namespaces in a series of using declarations in a case insensitive way.

For example, this code:

```cpp
namespace testing {
class A {};
class C {};
class E {};
}

namespace Testing {
class B {};
class D {};
}

using Testing::B;
using Testing::D;
using testing::A;
using testing::C;
using testing::E;
```

Is reformatted to this:

```cpp
namespace testing {
class A {};
class C {};
class E {};
} // namespace testing

namespace Testing {
class B {};
class D {};
} // namespace Testing

using testing::A;
using Testing::B;
using testing::C;
using Testing::D;
using testing::E;
```

Which I think is both surprising and makes reading more difficult.

It's not just a case insensitive sort though -- if you prefix `testing` with `::`, you get the same order from `clang-format`, interleaving `::testing::...` and `Testing::...` entries.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported ordering with the clang-format example and inspect the clang-format code that sorts using declarations. Add a regression test for namespaces whose names differ only by case, then verify that formatting no longer interleaves them unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.