-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
clang fails deduction on array when adding const qualification #119271
Comments
@llvm/issue-subscribers-clang-frontend Author: Barry Revzin (brevzin)
To be honest, I'm not entirely sure that this is a clang bug (and @zygoloid can put me in my place quickly enough).
Here's an interesting example: using size_t = decltype(sizeof(0));
template <size_t N>
void f(const int* const (&)[N]);
template <class T>
void g(T const* const*);
int main() {
int* pointers[3];
f(pointers); // clang: error, gcc: ok
g(pointers); // clang, gcc: ok
const int* const (&h)[3] = pointers; // clang, gcc: ok
} All three of these situations seem similar: we're taking an array of pointers to mutable
At the very least, it seems like |
EDG and MSVC agree with Clang that the call to I think there are two things at play here:
So, I think what's going on here is:
OK. So what's the actual disposition of the example? For implicit conversion:
Therefore accepting the reference binding is correct; everyone but MSVC gets this right. For the implicit conversion sequence:
Looks to me that:
And various implementations (maybe all of them) don't properly implement the rule that we always perform overload resolution, even for non-overloaded functions. |
There are days when I think I know this language. And then I ask you a question and read your answer... Thank you! |
CWG2803 adds specification for implicit conversion sequences that was omitted from CWG2352. I believe there is still a bug in the wording. [temp.deduct.call]/4 doesn't care whether the reference binding was direct or not, but
So the example falls into a gap in the template deduction wording. |
Ah right, and indeed both EDG and Clang are rejecting the call to |
I've requested a CWG issue: cplusplus/CWG#651 |
To be honest, I'm not entirely sure that this is a clang bug (and @zygoloid can put me in my place quickly enough).
Here's an interesting example:
All three of these situations seem similar: we're taking an array of pointers to mutable
int
(noconst
anywhere) and trying to addconst
in two layers:f
is trying to deduce a reference to an array of const pointers to constint
(gcc is okay with this, clang fails deduction saying it cannot matchconst int *
againstint*
)g
is trying to deduce a pointer to const pointer to constint
(which is similar, and both gcc and clang are fine with this)h
is just directly binding the same reference thatf
would have, except not in a template deduction context (likewise similar, both gcc and clang are fine with this too)At the very least, it seems like
f
andh
should either both be valid or both be invalid. So I think it's either a clang bug (so I'm in the right spot) or a C++ bug (and I should be writing this issue in a different spot).The text was updated successfully, but these errors were encountered: