]> granicus.if.org Git - clang/commitdiff
New test for when the subexpressions within a typeid are potentially evaluated. We...
authorDouglas Gregor <dgregor@apple.com>
Tue, 23 Jun 2009 15:32:13 +0000 (15:32 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 23 Jun 2009 15:32:13 +0000 (15:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73955 91177308-0d34-0410-b5e6-96231b3b80d8

test/CXX/basic/basic.def.odr/p2-typeid.cpp [new file with mode: 0644]

diff --git a/test/CXX/basic/basic.def.odr/p2-typeid.cpp b/test/CXX/basic/basic.def.odr/p2-typeid.cpp
new file mode 100644 (file)
index 0000000..7eb10ef
--- /dev/null
@@ -0,0 +1,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());
+}