OSDN Git Service

07aece6917fb9c342ee02a63a59d2e136ccd2926
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / debug / dwarf2 / template-func-params-7.C
1 // Contributed by Dodji Seketeli <dodji@redhat.com>
2 // Origin PR debug/30161
3 // { dg-options "-g -dA -std=c++0x" }
4 // { dg-do compile }
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.*?\\) DW_TAG_subprogram" 5 } }
10
11 // That makes 6 template type parameters.
12 // { dg-final {scan-assembler-times "DIE \\(0x.*?\\) DW_TAG_template_type_param" 6 } }
13 // { dg-final {scan-assembler-times "DW_AT_name: \"printf<int, char, int>\"" 1 } }
14 // { dg-final {scan-assembler-times "DW_AT_name: \"printf<char, int>\"" 1 } }
15 // { dg-final {scan-assembler-times "DW_AT_name: \"printf<int>\"" 1 } }
16 // { dg-final {scan-assembler-times "DW_AT_name: \"printf\"" 1 } }
17
18 // printf<int, char, int> and printf<char, int> have a pack expansion as
19 // function parameters. In the former, the elements of the parameter pack
20 // expansion are PackTypes#0, PackTypes#1 and the arguments are args#0 and
21 // args#1. In the later, the element of the parameter pack expansion
22 // is PackTypes#0 and the argument is args#0.
23 // { dg-final {scan-assembler-times "DW_AT_name: \"PackTypes#0\"" 2 } }
24 // { dg-final {scan-assembler-times "DW_AT_name: \"args#0\"" 2 } }
25 // { dg-final {scan-assembler-times "DW_AT_name: \"PackTypes#1\"" 1 } }
26 // { dg-final {scan-assembler-times "DW_AT_name: \"args#1\"" 1 } }
27
28 // { dg_final {scan-assembler-times "\.ascii \"T.0\"\[\t \]+.*?DW_AT_name" 3 } }
29
30 void
31 printf(const char* s)
32 {
33   /* Commented this to not pull std::cout into what should be
34      a simple test.
35   while (*s)
36     std::cout << *s++;
37   */
38 }
39
40 template<typename T, typename... PackTypes>
41 void
42 printf(const char* s,
43        T value,
44        PackTypes... args)
45 {
46   while (*s)
47     {
48       if (*s == '%' && *++s != '%')
49         {
50           /* std::cout << value; */
51           return printf(++s, args...);
52         }
53     }
54 }
55
56 void
57 foo ()
58 {
59   int x;
60   printf("%c %d", x, 'x', 3);
61 }