Consider the following code:
template<typename T>
struct A { };
// same as A, but with one extra defaulted parameter
template<typename T, typename F = int>
struct B { };
template<template<typename> typename T>
T<int> build() { return {}; }
int main()
{
build<A>(); // works in gcc and clang
build<B>(); // works in gcc, does not work in clang
}
g++ (7.3.0) compiles the code just fine, however, clang++ (5.0.1) emits the following:
example.cpp:14:5: error: no matching function for call to 'build'
build<B>(); // works in gcc, does not work in clang
^~~~~~~~
example.cpp:9:8: note: candidate template ignored: invalid
explicitly-specified argument for template parameter 'T'
T<int> build() { return {}; }
Which of the compilers is right?
Note: The important line is obviously:
template<template<typename> typename T>
Because both compilers are satisfied with:
template<template<typename...> typename T>
So the question is whether default values should be considered when passing template template arguments.
clang HEAD 7.0.0
andC++2a
. The output is similar to that in the question. Life demo – Cirilla