Issue 63852
Summary C++ compile error. - Non-const lvalue reference to type 'int[y - 2]'
Labels clang
Assignees
Reporter chichunchen
    For the following code snippet, gcc is able to compile without any warnings and errors, however, clang emits compile error code “lvalue_reference_bind_to_unrelated”.

gcc: https://godbolt.org/z/q3fEqKGb6
clang: https://godbolt.org/z/f51Ehd6s1 
Code snippet:
```
void
foo (int &x, int &y)
{
  int err = 0, i;
  int a[y - 2], b[y - 2];
  int (&c)[y - 2] = a, (&d)[y - 2] = b;
}
```

Error message from clang:
```
<source>:6:9: error: non-const lvalue reference to type 'int[y - 2]' cannot bind to a value of unrelated type 'int[y - 2]'
  int (&c)[y - 2] = a, (&d)[y - 2] = b;
        ^           ~
<source>:6:26: error: non-const lvalue reference to type 'int[y - 2]' cannot bind to a value of unrelated type 'int[y - 2]'
  int (&c)[y - 2] = a, (&d)[y - 2] = b;
                         ^           ~
2 errors generated.
```

The error message seems weird to me since the type it wants to bind is the same type.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to