I believe that this is a mistake in the GCC implementation of its extension to C ++ 14 auto . Here is a program that seems to be designed to work:
auto f(auto i) { return ""; } int main() { const char *s = f(1); return 0; }
It does not work, it fails with an error: the conversion from 'int to' const char * "is incorrect, because GCC for some reason determines that the return type must be the same as the parameter type.
The same error can make code that should be rejected, for example, what in your question, compile without problems.
Of course, this error does not affect compliance, because no valid C ++ 14 program can use auto parameters outside of lambdas.
Reportedly, a week ago, GCC developers reported bug # 64969 , resulting in another SO question about this .
source share