Clang Project

clang_source_code/test/CXX/basic/basic.def.odr/p2-typeid.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3// C++ [basic.def.odr]p2:
4//   An expression is potentially evaluated unless it [...] is the
5//   operand of the typeid operator and the expression does not
6//   designate an lvalue of polymorphic class type.
7
8// FIXME: This should really include <typeinfo>, but we don't have that yet.
9namespace std {
10  class type_info;
11}
12
13struct Poly {
14  virtual ~Poly();
15};
16
17struct NonPoly { };
18
19template<typename T, typename Result = T> 
20struct X {
21  Result f(T t) { return t + t; } // expected-error{{invalid operands}}
22
23  void g(T t) {
24    (void)typeid(f(t)); // expected-note{{here}}
25  }
26};
27
28void test(X<Poly> xp, X<Poly, Poly&> xpr, X<NonPoly> xnp, X<NonPoly, NonPoly&> xnpr) {
29  // These are okay (although GCC and EDG get them wrong).
30  xp.g(Poly());
31  xnp.g(NonPoly());
32  xnpr.g(NonPoly());
33
34  // Triggers an error (as it should);
35  xpr.g(Poly()); // expected-note{{instantiation of member function}}
36}
37