Narrow, invaluable context and template function

Consider the following code:

auto f() -> decltype(int{0.}, void()) { } int main() { f(); } 

It will not compile (as expected) the error:

narrowing the conversion of '0.0' from 'double' to 'int' inside {}

Both GCC and clang agree on this.
Now consider the following code:

 template <typename T> auto f(T) -> decltype(int{0.}, void()) { } int main(){ f(0); } 

In this case, clang 3.9 returns an error, and GCC 6.2 compiles without errors.

Is there a reason why narrowing the conversion should be taken in the case of a function template or is it a GCC error?


I am going to open the problem for GCC because, in my opinion, it should not compile, but I would like to know if there is something important missing in the function template.

+7
c ++ c ++ 11 templates decltype
source share

No one has answered this question yet.

See related questions:

1643
Why can templates be implemented only in the header file?
961
Where and why do I need to put the keywords "template" and "name-type"?
23
Narrowing conversion to bool in list initialization - weird behavior
eleven
Is gcc wrong to not diagnose conversion narrowing in template arguments without type?
10
Using auto and decltype to return a link from a function in a template class
10
Why can't a lambda be used in the context of constexpr when it is used to indicate a function?
4
Passing a function to a function variable template
3
GCC ICE (segfault) and clang compile just fine: is this valid code?
2
optional template argument causes overload ambiguity
one
Can the templates function return the type dependent on the same function template of the return type recursively?

All Articles