What type and default value does the single template parameter have in the following code?
template<auto = {}>
int getInt();
Clang with -Xclang -ast-dump only says:
| |-NonTypeTemplateParmDecl 0xcb77130 <line:1:10, col:18> col:15 'auto' depth 0 index 0
| | `-TemplateArgument expr
| | `-InitListExpr 0xcb77050 <col:17, col:18> 'void'
Consider this template:
It compiles successfully, but the default value can't actually be used:
You have to explicitly call it with a value, like
getInt<0>();It's the same with
template<auto = {}>: A default value is provided, but the type can't be deduced from the initializer, sogetInt()can't call that function template. You can only ever usegetInt<(initializer)>{}.If you're wondering what
automeans, it's a placeholder type. It's not deduced from the default, it's deduced from the initializer in the call (which may be the default if nothing is provided or otherwise deduced).So this is perfectly valid: