llvm / llvm/llvm-project

[Clang, C++20] Undefined symbol for redeclared friend function with requires.

Open
#181,564 2 comments 0 reactions 0 assignees View on GitHub
clang:frontend question
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Clang seems not to recognize that a friend function is redeclared, if it has "requires".

```
#include

template
struct A
{
friend constexpr inline void b(A) requires(i == 3)
{}
};

constexpr void b(A<3>);

void Do()
{
::b(A<3>());
}
```

Emits:
```
"Do()":
jmp "b(A<3ul>)"
```

This results in an unresolvable function reference at link time.

GCC seems to behave the same way, however MSVC gets it right.

If the "requires" is removed, everything works fine.

Contributor guide

Open the contributing guide

Research direction

Start by compiling and linking the supplied C++20 reproducer with Clang, then compare it with the version where requires is removed. Trace friend-function redeclaration and symbol generation, and add a regression test once the relevant compiler test area is identified; done means the example links and the regression test passes.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.