Alf P. Steinbach
unread,Jan 28, 2016, 1:24:43 PM1/28/16You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Not sure whether this code is formally correct (it doesn't compile with
g++):
<code>
#include <stdio.h>
template< class... Args >
auto format_for( Args... args, int last_arg )
-> char const*
{
// using Specifier = char const [3];
// static Specifier const s[] = { {'%', 'f'+(0*args), ' '}...,
{'%', 'f', 0} };
return reinterpret_cast<char const*>( "" );
}
auto main() -> int
{
printf( "'%s'\n", format_for( 5, 2, 1 ) );
}
</code>
Anyway it crashes Visual C++ 2015 update 1:
<example>
C:\my\forums\so\081> cl printf.cpp /Feb
printf.cpp
printf.cpp(14): fatal error C1001: An internal error has occurred in the
compiler.
(compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\cxx\dymto.c', line 6771)
To work around this problem, try simplifying or changing the program
near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
C:\my\forums\so\081> g++ printf.cpp
printf.cpp: In function 'int main()':
printf.cpp:14:43: error: no matching function for call to
'format_for(int, int, int)'
printf( "'%s'\n", format_for( 5, 2, 1 ) );
^
printf.cpp:4:6: note: candidate: template<class ... Args> const char*
format_for(Args ..., int)
auto format_for( Args... args, int last_arg )
^
printf.cpp:4:6: note: template argument deduction/substitution failed:
printf.cpp:14:43: note: candidate expects 1 argument, 3 provided
printf( "'%s'\n", format_for( 5, 2, 1 ) );
^
</example>
I've posted an SO question about it, and I will probably post a bug
report to Microsoft Connect if or when I learn what to expect as correct
behavior, or after waiting some resonable time for that.
Cheers,
- Alf