llvm / llvm/llvm-project

Clang rejects implicit conversion from an integer lvalue reference to another integer rvalue reference via a conversion operator

Open
#180,476 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend diverges-from:edg diverges-from:gcc diverges-from:msvc rejects-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following program is rejected by clang but accepted by both gcc and msvc. [Demo](https://godbolt.org/z/1ofEdhKzW)
```
#include

struct S
{
operator long &() const
{
exit(0);
}
};

int main() { int &&a((S())); }
```
Clang says:
```
:9:20: error: no viable conversion from 'S' to 'int'
9 | int main() { int &&a((S())); }
| ^ ~~~~~
:4:2: note: candidate function
4 | operator long &() const {
|
```

Contributor guide

Open the contributing guide

Research direction

Start with the reduced C++ reproducer in the issue and compare Clang's diagnostic with the accepted behavior shown for GCC and MSVC in the linked Compiler Explorer demo. Trace the compiler's implicit-conversion handling for the conversion operator, then verify that the reproducer is accepted without the reported error.

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
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.