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. |
9 | namespace std { |
10 | class type_info; |
11 | } |
12 | |
13 | struct Poly { |
14 | virtual ~Poly(); |
15 | }; |
16 | |
17 | struct NonPoly { }; |
18 | |
19 | template<typename T, typename Result = T> |
20 | struct 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 | |
28 | void 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 | |