Skip to content

clang fails deduction on array when adding const qualification #119271

@brevzin

Description

@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 int (no const anywhere) and trying to add const in two layers:

  • f is trying to deduce a reference to an array of const pointers to const int (gcc is okay with this, clang fails deduction saying it cannot match const int * against int*)
  • g is trying to deduce a pointer to const pointer to const int (which is similar, and both gcc and clang are fine with this)
  • h is just directly binding the same reference that f 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 and h 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issue

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions