Merged revisions 208012,208018-208019,208021,208023-208030,208033,208037,208040-20804...
[official-gcc.git] / main / gcc / testsuite / g++.dg / debug / dwarf2 / template-func-params-7.C
blob7bdcc4d46ca6244d762e8e4d1906e2cf0257acab
1 // Contributed by Dodji Seketeli <dodji@redhat.com>
2 // Origin PR debug/30161
3 // { dg-options "-g -dA -fno-merge-debug-strings" }
4 // { dg-do compile { target c++11 } }
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 } }
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 } }
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 } }
28 void
29 printf(const char* s)
31   /* Commented this to not pull std::cout into what should be
32      a simple test.
33   while (*s)
34     std::cout << *s++;
35   */
38 template<typename T, typename... PackTypes>
39 void
40 printf(const char* s,
41        T value,
42        PackTypes... args)
44   while (*s)
45     {
46       if (*s == '%' && *++s != '%')
47         {
48           /* std::cout << value; */
49           return printf(++s, args...);
50         }
51     }
54 void
55 foo ()
57   int x;
58   printf("%c %d", x, 'x', 3);