* decl.c (make_typename_type): s/parameters/arguments/.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / auto9.C
blob40b4ef2233e3dd0e51123b646182b62322753173
1 // PR c++/37962
2 // Negative test for auto
3 // { dg-do compile { target c++11 } }
5 #include <typeinfo>
6 #include <stdarg.h>
7 #include <stddef.h>
9 int i = *(auto *) 0;                            // { dg-error "auto" }
10 struct A *p = (auto *) 0;                       // { dg-error "auto" }
11 int *q = static_cast <auto *>(0);               // { dg-error "auto" }
12 const int *r = const_cast <auto *>(q);          // { dg-error "auto" }
13 const std::type_info &t1 = typeid (auto);       // { dg-error "auto" }
14 const std::type_info &t2 = typeid (auto *);     // { dg-error "auto" }
16 struct A
18   operator auto ();                             // { dg-error "auto" "" { target { ! c++14 } } }
19   operator auto *();                            // { dg-error "auto" "" { target { ! c++14 } } }
22 struct A2
24   operator auto () -> int;                      // { dg-error "invalid use of|trailing return type" }
25   operator auto*() -> int;                      // { dg-error "invalid use of|trailing return type" }
28 template <typename> struct B
30   enum { e };
33 template <typename T> struct C
35   C () : i () {}
36   int i;
39 bool d = (auto (A::*)()) 0;                     // { dg-error "auto" }
41 void
42 foo ()
44   __extension__ (auto) { 0 };                   // { dg-error "auto" }
45   C<int> c;
46   dynamic_cast<auto> (c);                       // { dg-error "auto" }
47   reinterpret_cast<auto> (c);                   // { dg-error "auto" }
48   int i = auto (0);                             // { dg-error "auto" }
49   auto p1 = new (auto);                         // { dg-error "auto" }
50   auto p2 = new (auto) (42);                    // { dg-error "invalid use of|deduce" }
51   offsetof (auto, fld);                         // { dg-error "auto" }
52   offsetof (auto *, fld);                       // { dg-error "auto" }
53   sizeof (auto);                                // { dg-error "auto" }
54   sizeof (auto *);                              // { dg-error "auto" }
57 void
58 foo2 (void)
60   __alignof__ (auto);                           // { dg-error "auto" }
61   __alignof__ (auto *);                         // { dg-error "auto" }
62   __typeof__ (auto) v1;                         // { dg-error "auto" }
63   __typeof__ (auto *) v2;                       // { dg-error "auto" }
64   __is_class (auto);                            // { dg-error "auto|expected" }
65   __is_pod (auto *);                            // { dg-error "auto|expected" }
66   __is_base_of (int, auto);                     // { dg-error "auto|expected" }
67   __is_base_of (auto, int);                     // { dg-error "auto|expected" }
68   __is_base_of (auto, auto *);                  // { dg-error "auto|expected" }
71 B<auto> b;                                      // { dg-error "auto|invalid" }
72 C<auto> c;                                      // { dg-error "auto|invalid" }
73 C<auto *> c2;                                   // { dg-error "auto|invalid" }
75 enum : auto { EE = 0 };                         // { dg-error "must be an integral type" }
76 enum struct D : auto * { FF = 0 };              // { dg-error "must be an integral type|declar|expected" }
78 void
79 bar ()
81   try { } catch (auto i) { }                    // { dg-error "parameter" }
82   try { } catch (auto) { }                      // { dg-error "parameter" }
83   try { } catch (auto *i) { }                   // { dg-error "parameter" }
84   try { } catch (auto *) { }                    // { dg-error "parameter" }
87 void
88 baz (int i, ...)
90   va_list ap;
91   va_start (ap, i);
92   va_arg (ap, auto);                            // { dg-error "invalid use of" }
93   va_arg (ap, auto *);                          // { dg-error "invalid use of|expected" }
94   va_arg (ap, auto &);                          // { dg-error "invalid use of|expected" }
95   va_end (ap);
98 template <typename T = auto> struct E {};       // { dg-error "invalid use of" }
99 template <class T = auto *> struct F {};        // { dg-error "invalid use of|expected" }
101 auto fnlate () -> auto;                         // { dg-error "invalid use of" "" { target { ! c++14 } } }
102 auto fnlate2 () -> auto *;                      // { dg-error "invalid use of|expected" "" { target { ! c++14 } } }
104 void
105 badthrow () throw (auto)                        // { dg-error "invalid use of" }
106 {                                               // { dg-error "dynamic exception specification" "" { target c++17 } .-1 }
107 }                                               // { dg-warning "deprecated" "" { target { ! c++17 } } .-2 }
109 void
110 badthrow2 () throw (auto &)                     // { dg-error "invalid use of|expected" }
111 {                                               // { dg-error "dynamic exception specification" "" { target c++17 } .-1 }
112 }                                               // { dg-warning "deprecated" "" { target { ! c++17 } } .-2 }
114 template <auto V = 4> struct G {};              // { dg-error "auto" "" { target { ! c++17 } } }
116 template <typename T> struct H { H (); ~H (); };
117 H<auto> h;                                      // { dg-error "invalid|initializer" }
119 void qq (auto);                // { dg-error "auto" "" { target { ! concepts } } }
120 void qr (auto*);               // { dg-error "auto" "" { target { ! concepts } } }
122 // PR c++/46145
123 typedef auto autot;             // { dg-error "auto" }