aboutsummaryrefslogtreecommitdiff
path: root/test/CXX/basic/basic.def.odr/p2-typeid.cpp
blob: 881212d74ba4ae90213788205950c8bd21480d96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// RUN: clang-cc -fsyntax-only -verify %s

// C++ [basic.def.odr]p2:
//   An expression is potentially evaluated unless it [...] is the
//   operand of the typeid operator and the expression does not
//   designate an lvalue of polymorphic class type.

// FIXME: This should really include <typeinfo>, but we don't have that yet.
namespace std {
  class type_info;
}

struct Poly {
  virtual ~Poly();
};

struct NonPoly { };

template<typename T, typename Result = T> 
struct X {
  Result f(T t) { return t + t; } // expected-error{{invalid operands}}

  void g(T t) {
    (void)typeid(f(t)); // expected-note{{here}}
  }
};

void test(X<Poly> xp, X<Poly, Poly&> xpr, X<NonPoly> xnp, X<NonPoly, NonPoly&> xnpr) {
  // These are okay (although GCC and EDG get them wrong).
  xp.g(Poly());
  xnp.g(NonPoly());
  xnpr.g(NonPoly());

  // Triggers an error (as it should);
  xpr.g(Poly()); // expected-note{{instantiation of member function}}
}