Issue 123033
Summary [clang] Ambiguity between function declaration and definition when using pack indexing
Labels clang
Assignees
Reporter FSK-idk
    Godbolt: https://godbolt.org/z/817Kve9zc

It seems that clang can't compile code if I decide to separate the declaration and implementation of a function with pack indexing in some cases. However, if you comment out the declaration, it will compile.

```cpp
#include <concepts>
#include <iostream>


// in requires _expression_

template <class... Types>
requires std::same_as<Types...[0], int>
void print(double d);

template <class... Types>
requires std::same_as<Types...[0], int>
void print(double d) {
 std::cout << "it doesn't work " << static_cast<Types...[0]>(d) << "\n";
}


// in return type

template <class... Types>
Types...[0] convert(double d);

template <class... Types>
Types...[0] convert(double d) {
    return static_cast<Types...[0]>(d);
}


int main() {
 print<int, int>(12.34);
    std::cout << "convert: " << convert<int, int>(12.34) << "\n";

    return 0;
}
```

Output
```
<source>:30:5: error: call to 'print' is ambiguous
   30 |     print<int, int>(12.34);
      | ^~~~~~~~~~~~~~~
<source>:9:6: note: candidate function [with Types = <int, int>]
    9 | void print(double d);
      |      ^
<source>:13:6: note: candidate function [with Types = <int, int>]
   13 | void print(double d) {
      |      ^
<source>:31:33: error: call to 'convert' is ambiguous
 31 |     std::cout << "convert: " << convert<int, int>(12.34) << "\n";
 |                                 ^~~~~~~~~~~~~~~~~
<source>:21:13: note: candidate function [with Types = <int, int>]
   21 | Types...[0] convert(double d);
      |             ^
<source>:24:13: note: candidate function [with Types = <int, int>]
   24 | Types...[0] convert(double d) {
 |             ^
2 errors generated.
Compiler returned: 1
```


_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to