C++: show location of unclosed extern "C" specifications
[official-gcc.git] / gcc / testsuite / g++.dg / template / extern-c.C
blobc0dd7cb66d5e437f48619ddf9a1f7b5cf2ad2a63
1 template <typename T> void specializable (T);
3 /* Invalid template: within "extern C".  */
5 extern "C" { // { dg-message "1: 'extern .C.' linkage started here" }
7 template <typename T> // { dg-error "template with C linkage" }
8 void within_extern_c_braces (void);
12 /* Valid template: not within "extern C".  */
14 template <typename T>
15 void not_within_extern_c (void);
18 /* Invalid specialization: within "extern C".  */
20 extern "C" { // { dg-message "1: 'extern .C.' linkage started here" }
22 template <>  // { dg-error "template specialization with C linkage" }
23 void specializable (int);
28 /* Valid specialization: not within "extern C".  */
29 template <>
30 void specializable (char);
33 /* Example of extern C without braces.  */
35 extern "C" template <typename T> // { dg-line open_extern_c_no_braces }
36 void within_extern_c_no_braces (void);
37 // { dg-error "12: template with C linkage" "" { target *-*-* } open_extern_c_no_braces }
38 // { dg-message "1: 'extern .C.' linkage started here" "" { target *-*-* } open_extern_c_no_braces }
41 /* Nested extern "C" specifications.
42    We should report within the innermost extern "C" that's still open.  */
44 extern "C" {
45   extern "C" { // { dg-line middle_open_extern_c }
46     extern "C" {
47     }
49     template <typename T>  // { dg-error "template with C linkage" }
50     void within_nested_extern_c (void);
51     // { dg-message "3: 'extern .C.' linkage started here" "" { target *-*-* } middle_open_extern_c }
53     extern "C++" {
54       /* Valid template: within extern "C++".  */
55       template <typename T>
56       void within_nested_extern_cpp (void);
58       extern "C" {  // { dg-line last_open_extern_c }
59         /* Invalid template: within "extern C".  */
60         template <typename T> // { dg-error "template with C linkage" }
61         void within_extern_c_within_extern_cpp (void);
62         // { dg-message "7: 'extern .C.' linkage started here" "" { target *-*-* } last_open_extern_c } 
63       }
64     }
65   }