C++ Logo

std-discussion

Advanced search

Re: The standard does not specify when to supply default arguments as template arguments

From: jim x <xmh970252187_at_[hidden]>
Date: Fri, 17 Jul 2020 11:06:39 +0800
template<typename T, typename U = T>
struct Test{};

template<typename T>
void func(Test<T> /*#1*/){
}

int main(){
func(Test<int,char>{});
}

For this case, the report error is "deduced conflicting types for
parameter 'T' ('int' and 'char')", please see
https://godbolt.org/z/MnWGYq, It sounds like the function parameter
would be the form as Test<T,T>, then deduced Test<T,T> from Test<int,
char>, then T will have two different type values. So, I wonder that
Does the compiler view Test<T> at #1 as Test<T,T>. At this point,
there's no instantiation happening, hence , how does the rule "When a
simple-template-id does not name a function, a default
template-argument is implicitly instantiated when the value of that
default argument is needed." applies to this case. In my mind, the
default argument is required at #1, but there shall be no
instantiation.

Received on 2020-07-16 22:10:11