| 1 |
// Contributed by Dodji Seketeli <[email protected]> |
| 2 |
// Origin PR debug/30161 |
| 3 |
// { dg-options "-gdwarf-2 -dA -fno-merge-debug-strings" } |
| 4 |
// { dg-do compile { target c++11 } } |
| 5 |
|
| 6 |
// There must be 5 subprograms generated: |
| 7 |
// printf(const char*), printf<int, char, int>, |
| 8 |
// printf<char, int>, printf<int> and foo(). |
| 9 |
// { dg-final { scan-assembler-times "DIE \\(0x\[^\n\]*\\) DW_TAG_subprogram" 5 } } |
| 10 |
|
| 11 |
// That makes 6 template type parameters. |
| 12 |
// { dg-final { scan-assembler-times "DIE \\(0x\[^\n\]*\\) DW_TAG_template_type_param" 6 } } |
| 13 |
// { dg-final { scan-assembler-times "\"printf<int, char, int>.0\"\[^\n\]*DW_AT_name" 1 } } |
| 14 |
// { dg-final { scan-assembler-times "\"printf<char, int>.0\"\[^\n\]*DW_AT_name" 1 } } |
| 15 |
// { dg-final { scan-assembler-times "\"printf<int>.0\"\[^\n\]*DW_AT_name" 1 } } |
| 16 |
// { dg-final { scan-assembler-times "\"printf.0\"\[^\n\]*DW_AT_name" 1 } } |
| 17 |
|
| 18 |
// printf<int, char, int> and printf<char, int> have a pack expansion as |
| 19 |
// function parameters. There should then be 3 |
| 20 |
// DW_TAG_GNU_template_parameter_pack and 3 DW_TAG_GNU_formal_parameter_pack DIEs |
| 21 |
// { dg-final { scan-assembler-times "DIE \\(0x\[^\n\]*\\) DW_TAG_GNU_template_parameter_pack" 3 } } |
| 22 |
// { dg-final { scan-assembler-times "DIE \\(0x\[^\n\]*\\) DW_TAG_GNU_formal_parameter_pack" 3 } } |
| 23 |
// These 3 function template instantiations has a total of 3 template |
| 24 |
// parameters named T. |
| 25 |
// { dg-final { scan-assembler-times "\.ascii \"T.0\"\[\t \]+\[^\n\]*DW_AT_name" 3 } } |
| 26 |
// And the packs also have names. |
| 27 |
// { dg-final { scan-assembler-times "\.ascii \"PTs.0\"\[\t \]+\[^\n\]*DW_AT_name" 3 } } |
| 28 |
// { dg-final { scan-assembler-times "\.ascii \"args.0\"\[\t \]+\[^\n\]*DW_AT_name" 3 } } |
| 29 |
|
| 30 |
|
| 31 |
void |
| 32 |
printf(const char* s) |
| 33 |
{ |
| 34 |
/* Commented this to not pull std::cout into what should be |
| 35 |
a simple test. |
| 36 |
while (*s) |
| 37 |
std::cout << *s++; |
| 38 |
*/ |
| 39 |
} |
| 40 |
|
| 41 |
template<typename T, typename... PTs> |
| 42 |
void |
| 43 |
printf(const char* s, |
| 44 |
T value, |
| 45 |
PTs... args) |
| 46 |
{ |
| 47 |
while (*s) |
| 48 |
{ |
| 49 |
if (*s == '%' && *++s != '%') |
| 50 |
{ |
| 51 |
/* std::cout << value; */ |
| 52 |
return printf(++s, args...); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
void |
| 58 |
foo () |
| 59 |
{ |
| 60 |
int x; |
| 61 |
printf("%c %d", x, 'x', 3); |
| 62 |
} |