Issue 91300
Summary Windows Clang finds ambiguity after function template call site
Labels clang
Assignees
Reporter joshuamaiche
    The repro is more straightforward than the tile.

**main.cpp**
```
int GetVal1() { return 0; }

template <typename T> int GetVal2() { return GetVal1(); }

int result1 = GetVal2<int>(); // Does not compile
int result2 = GetVal1(); // Compiles

int GetVal1(int value = 0) { return 0; }

int main() {}
```

**Console**
```
>clang main.cpp
main.cpp:3:46: error: call to 'GetVal1' is ambiguous
template <typename T> int GetVal2() { return GetVal1(); }
 ^~~~~~~
main.cpp:1:5: note: candidate function
int GetVal1() { return 0; }
    ^
main.cpp:8:5: note: candidate function
int GetVal1(int value = 0) { return 0; }
    ^
1 error generated.
```

`GetVal1()` is defined, then overloaded in an ambiguous manner. However, before this ambiguity is introduced, the function template `GetVal2()`, which uses `GetVal1()`, is defined and called. This still results in the compiler complaining that the call to `GetVal1()` is ambiguous.

I'm not certain if this is allowed by the standard, but it's at least inconsistent between different flavors of Clang. The same major version of Linux Clang compiles the code without any errors.

This retroactive ambiguity means that files included later can interfere with files included earlier in code.

**Windows console**
```
>clang --version
clang version 16.0.5
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\bin
```
**Linux console**
```
$ clang-16 --version
Ubuntu clang version 16.0.6 (++20231112100510+7cbf1a259152-1~exp1~20231112100554.106)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to