Clang 22 and 23: std::same_as ignores access specifiers
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following code fails to compile with clang 22 and clang trunk, but compiles successfully with clang 21 and gcc 15, 16:
Compiler explorer link: https://godbolt.org/z/jdcbq1Gj9
Code:
```c++
#include
template
struct GetThing {
static_assert(false, "no match");
};
template
requires std::same_as
struct GetThing {
static constexpr const bool value = true;
};
template
requires std::same_as
struct GetThing {
static constexpr const bool value = true;
};
class Something {
public:
using TT = int;
private:
using T = bool;
};
int main() {
//static_assert(std::same_as); // error: 'T' is a private member of 'Something' - as expected
static_assert(std::same_as);
static_assert(GetThing::value); // ambiguous partial specializations of 'GetThing' - Only on clang 22 and 23
}
```
Error message:
```
:30:19: error: ambiguous partial specializations of 'GetThing'
30 | static_assert(GetThing::value); // ambiguous partial specializations of 'GetThing' - Only on clang 22 and 23
| ^
:10:8: note: partial specialization matches [with T = Something]
10 | struct GetThing {
| ^
:16:8: note: partial specialization matches [with T = Something]
16 | struct GetThing {
| ^
1 error generated.
Compiler returned: 1
```
Contributor guide
Research direction
Start with the Compiler Explorer link and reproduce the ambiguity on Clang 22 or trunk, then compare the result with Clang 21 and GCC 15 or 16. No repository file or test is named; the issue is done when std::same_as no longer causes the private alias to make the partial specializations ambiguous while the public alias continues to match.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100