[cfe-commits] r73955 - /cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp
Douglas Gregor
dgregor at apple.com
Tue Jun 23 08:32:22 PDT 2009
Author: dgregor
Date: Tue Jun 23 10:32:13 2009
New Revision: 73955
URL: http://llvm.org/viewvc/llvm-project?rev=73955&view=rev
Log:
New test for when the subexpressions within a typeid are potentially evaluated. We seem to be the only ones to get this right.
Added:
cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp (with props)
Added: cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp?rev=73955&view=auto
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp (added)
+++ cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp Tue Jun 23 10:32:13 2009
@@ -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());
+}
Propchange: cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/basic/basic.def.odr/p2-typeid.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list