Skip to content

[Clang] Clang and GCC diverge on array reference overload resolution with int const(&)[] vs int const(&)[1] #165369

@Xniao

Description

@Xniao

Generated by Fuzzer.

GCC correctly accepts the call as unambiguous, selecting the more specific [1] overload, while Clang incorrectly rejects it with an "ambiguous call" error.
Reproducer: https://godbolt.org/z/4YTerK8Ws

Program:

int f2(int const (&)[]) { return 1; }
int f2(int const (&)[1]) {
  const int size = 1;
  int array[size] = {42};
  if (array[0] > 0) {
    int value_2 = f2(array);
    return value_2;
  }
  return 2;
}

int main() {
  if (f2({}) != 1) return -1;
  if (f2({1}) != 2) return -1;
  return 0;
}

Clang rejects it with following error message:

<source>:6:19: error: call to 'f2' is ambiguous
    6 |     int value_2 = f2(array);
      |                   ^~
<source>:1:5: note: candidate function
    1 | int f2(int const (&)[]) { return 1; }
      |     ^
<source>:2:5: note: candidate function
    2 | int f2(int const (&)[1]) {
      |     ^
1 error generated.
Compiler returned: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions