| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
void f() |
| 4 |
{ |
| 5 |
(void)typeid(int); |
| 6 |
#if __cplusplus >= 202002L |
| 7 |
// expected-error@-2 {{you need to include <typeinfo> or import std before using the 'typeid' operator}} |
| 8 |
#else |
| 9 |
// expected-error@-4 {{you need to include <typeinfo> before using the 'typeid' operator}} |
| 10 |
#endif |
| 11 |
} |
| 12 |
|
| 13 |
namespace std { |
| 14 |
struct type_info { const char *name; }; |
| 15 |
} |
| 16 |
|
| 17 |
void g() |
| 18 |
{ |
| 19 |
(void)typeid(int); |
| 20 |
} |
| 21 |
|
| 22 |
struct X; // expected-note 3{{forward declaration}} |
| 23 |
|
| 24 |
void g1(X &x) { |
| 25 |
(void)typeid(X); // expected-error{{'typeid' of incomplete type 'X'}} |
| 26 |
(void)typeid(X&); // expected-error{{'typeid' of incomplete type 'X'}} |
| 27 |
(void)typeid(x); // expected-error{{'typeid' of incomplete type 'X'}} |
| 28 |
} |
| 29 |
|
| 30 |
void h(int i) { |
| 31 |
char V[i]; |
| 32 |
typeid(V); // expected-error{{'typeid' of variably modified type 'char[i]'}} |
| 33 |
typeid(char [i]); // expected-error{{'typeid' of variably modified type 'char[i]'}} |
| 34 |
} |
| 35 |
|
| 36 |
// expected-note@+1 {{read of object 'typeid(int).name' whose value is not known}} |
| 37 |
constexpr const char *name = typeid(int).name; // expected-error {{constant expression}} |