Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous overload on C++ structure returning _Float16 #56963

Open
thiagomacieira opened this issue Aug 5, 2022 · 1 comment
Open

Ambiguous overload on C++ structure returning _Float16 #56963

thiagomacieira opened this issue Aug 5, 2022 · 1 comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@thiagomacieira
Copy link

thiagomacieira commented Aug 5, 2022

struct Float16
{
    _Float16 f; operator _Float16() const { return f; }
}; 
float f(float f, _Float16 f16) { return f + f16; }
float f(float f, Float16 f16) { return f + f16; }

Compile with either -march=sapphirerapids or -target aarch64-linux.

GCC 12 compiles fine. Clang fails with:

test.cpp:6:42: error: use of overloaded operator '+' is ambiguous (with operand types 'float' and 'Float16')
float f(float f, Float16 f16) { return f + f16; }
                                       ~ ^ ~~~
test.cpp:6:42: note: built-in candidate operator+(float, float)
test.cpp:6:42: note: built-in candidate operator+(float, double)
test.cpp:6:42: note: built-in candidate operator+(float, long double)
test.cpp:6:42: note: built-in candidate operator+(float, int)
test.cpp:6:42: note: built-in candidate operator+(float, long)
test.cpp:6:42: note: built-in candidate operator+(float, long long)
test.cpp:6:42: note: built-in candidate operator+(float, __int128)
test.cpp:6:42: note: built-in candidate operator+(float, unsigned int)
test.cpp:6:42: note: built-in candidate operator+(float, unsigned long)
test.cpp:6:42: note: built-in candidate operator+(float, unsigned long long)
test.cpp:6:42: note: built-in candidate operator+(float, unsigned __int128)
1 error generated.

Note that there's no offering for operator+(float, _Float16) in the listing, though that addition does work as seen in the previous line. The problem appears with the cast operator present only.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Aug 5, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 5, 2022

@llvm/issue-subscribers-clang-frontend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants