C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: The standard does not specify when to supply default arguments as template arguments
From: jim x (xmh970252187_at_[hidden])
Date: 2020-07-16 22:06:39


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.


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups