Issue |
138420
|
Summary |
Unnecessary instantiation of templated function passed as a template parameter causes valid C++ code to fail compilation
|
Labels |
new issue
|
Assignees |
|
Reporter |
TRDario
|
The following code snippet compiles with MSVC and GCC, but fails to compile with Clang 20.1.0:
```
#include <unordered_map>
#include <vector>
template <class T>
concept standard_layout = std::is_standard_layout_v<T>;
template <class T, template <class...> class Z> struct is_specialization_of : std::false_type {};
template <class... Args, template <class...> class Z> struct is_specialization_of<Z<Args...>, Z> : std::true_type {};
template <class T, template <class...> class Z>
concept specialization_of = is_specialization_of<T, Z>::value;
template <class T> using fn = T (*)();
template <class T> T foo()
{
static_assert(!specialization_of<T, std::pair>, "Compilation error!");
return T{};
}
template <specialization_of<std::vector> T, fn<typename T::value_type> D> T bar()
{
D();
return T{};
}
template <specialization_of<std::unordered_map> T, fn<typename T::key_type> D1, fn<typename T::mapped_type> D2> T bar()
{
D1();
D2();
return T{};
}
int main()
{
bar<std::unordered_map<int, char>, foo, foo>();
}
```
It appears that in this example despite the std::vector overload of 'bar' not being chosen, 'foo<std::pair<int, char>>' is still instantiated and the error it emits causes the compilation to fail.
The error does not occur if 'foo' is a regular overloaded function, i.e replacing it with:
```
void foo(int) {}
void foo(char) {}
void foo(std::pair<int, char>) = delete;
```
does not result in any compilation errors.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs