llvm / llvm/llvm-project

[Clang] Clang incorrectly calculates constraints involving private members and multiple nested classes of the same name

Open
#198,716 6 comments 0 reactions 0 assignees View on GitHub
clang:frontend concepts diverges-from:edg diverges-from:gcc diverges-from:msvc regression:22
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Since Clang 22, Clang starts rejecting the following code snippet ([Godbolt link](https://godbolt.org/z/c89Tx5EeG)), which is perhaps incorrect.

Note that Clang behaves as expected if two nested classes are of different names.

```C++
struct A {
class Nested { // N.B. Both nested classes have the same name.
private:
static void test_function();
};
};

template
concept has_member_test_function = requires {
T::test_function();
};

static_assert(!has_member_test_function);

struct B {
struct Nested { // N.B. Both nested classes have the same name.
template
requires has_member_test_function
Nested(const T&);
};
};

template
concept quick_convertible_to = requires(From&& t, void (&fun)(To)) {
fun(static_cast(t));
};

static_assert(!quick_convertible_to);
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided C++ reproducer from the Godbolt link with Clang 22 and a comparison version, confirming the rejection involving same-named nested classes and private members. Trace the constraint and conversion checks implicated by the reproducer; done means Clang accepts the code with both static assertions remaining valid.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.