Clang Project

clang_source_code/test/SemaCXX/typeid.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3void f()
4{
5  (void)typeid(int); // expected-error {{you need to include <typeinfo> before using the 'typeid' operator}}
6}
7
8namespace std {
9  class type_info;
10}
11
12void g()
13{
14  (void)typeid(int);
15}
16
17struct X; // expected-note 3{{forward declaration}}
18
19void g1(X &x) {
20  (void)typeid(X); // expected-error{{'typeid' of incomplete type 'X'}}
21  (void)typeid(X&); // expected-error{{'typeid' of incomplete type 'X'}}
22  (void)typeid(x); // expected-error{{'typeid' of incomplete type 'X'}}
23}
24
25void h(int i) {
26  char V[i];
27  typeid(V);        // expected-error{{'typeid' of variably modified type 'char [i]'}}
28  typeid(char [i]); // expected-error{{'typeid' of variably modified type 'char [i]'}}
29}
30