llvm / llvm/llvm-project

[clang][Sema] Ambiguous overload resolution is accepted w/o error

Open
#224,499 2 comments 0 reactions 1 assignee Claimed by @Benjins View on GitHub
accepts-invalid c++20 clang:frontend generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following C++ code:
```cpp
template struct S {
int f() const requires true { return 1; }
int f() volatile { return 2; }
};
int test() { S s; return s.f(); }
```

when compiled with `-std=c++20` will be accepted by Clang w/o any errors. GCC rejects it with `error: call of overloaded 'f()' is ambiguous`, and my understanding is that it should be rejected (two possible overloads, neither one resolves ). Additionally, removing the `requires true` expression will also correctly be rejected.

Godbolt link: https://godbolt.org/z/n9o5T4rnc

From the code, I believe the error is here:
https://github.com/llvm/llvm-project/blob/b3d93594e556278609c9c1815f3ad93d1d49d9fb/clang/lib/Sema/SemaOverload.cpp#L10978-L10983

where the check is tautological (`hasSameType` will always return true). As an aside, I grepped for other calls to `hasSameType` and didn't find any other instances of the tautological comparison aside this one. Fixing that site does seem to start correctly rejecting the repro

I verified this still happens on latest trunk, a56ce734ca42c1fa10e50d3a5b4af336cddd7b5e

Disclosure: this reproducer was created by an LLM to stress-test the Clang frontend (rather than being found in real-world code). However, I have done my best to confirm on my own that it is a genuine issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.