[Clang] Clang and GCC diverge on array reference overload resolution with int const(&)[] vs int const(&)[1]
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
**_Generated by Fuzzer._**
GCC correctly accepts the call as unambiguous, selecting the more specific [1] overload, while Clang incorrectly rejects it with an "ambiguous call" error.
Reproducer: https://godbolt.org/z/4YTerK8Ws
Program:
```cpp
int f2(int const (&)[]) { return 1; }
int f2(int const (&)[1]) {
const int size = 1;
int array[size] = {42};
if (array[0] > 0) {
int value_2 = f2(array);
return value_2;
}
return 2;
}
int main() {
if (f2({}) != 1) return -1;
if (f2({1}) != 2) return -1;
return 0;
}
```
Clang rejects it with following error message:
```bash
:6:19: error: call to 'f2' is ambiguous
6 | int value_2 = f2(array);
| ^~
:1:5: note: candidate function
1 | int f2(int const (&)[]) { return 1; }
| ^
:2:5: note: candidate function
2 | int f2(int const (&)[1]) {
| ^
1 error generated.
Compiler returned: 1
```
Contributor guide
Research direction
Start with the Godbolt reproducer and compare Clang's overload-resolution diagnostics with GCC for the two array-reference overloads. Trace the relevant Clang semantic-analysis entry point, then find or add a regression test showing that the call is unambiguous and selects the [1] overload.
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