aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-06-23 15:32:13 +0000
committerDouglas Gregor <dgregor@apple.com>2009-06-23 15:32:13 +0000
commit33a3907db98dd79728f8f887f0468d3d98c49fcf (patch)
tree966a587541e6b5742fafb236e0d1ce74c921c2aa
parentd91ee27950ef5c321db1ac2aa5becb75ffe7cb14 (diff)
New test for when the subexpressions within a typeid are potentially evaluated. We seem to be the only ones to get this right.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73955 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/CXX/basic/basic.def.odr/p2-typeid.cpp36
1 files changed, 36 insertions, 0 deletions
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
index 0000000000..7eb10ef52e
--- /dev/null
+++ b/test/CXX/basic/basic.def.odr/p2-typeid.cpp
@@ -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());
+}