summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGenCXX/dynamic_cast-no-rtti.cpp26
-rw-r--r--clang/test/SemaCXX/no-rtti.cpp14
2 files changed, 40 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/dynamic_cast-no-rtti.cpp b/clang/test/CodeGenCXX/dynamic_cast-no-rtti.cpp
new file mode 100644
index 00000000000..2060e1d5453
--- /dev/null
+++ b/clang/test/CodeGenCXX/dynamic_cast-no-rtti.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -emit-llvm %s -verify -fno-rtti -o - | FileCheck %s
+// expected-no-diagnostics
+
+struct A {
+ virtual ~A(){};
+};
+
+struct B : public A {
+ B() : A() {}
+};
+
+// An upcast can be resolved statically and can be used with -fno-rtti, iff it
+// does not use runtime support.
+A *upcast(B *b) {
+ return dynamic_cast<A *>(b);
+// CHECK: define %struct.A* @_Z6upcastP1B
+// CHECK-NOT: call i8* @__dynamic_cast
+}
+
+// A NoOp dynamic_cast can be used with -fno-rtti iff it does not use
+// runtime support.
+B *samecast(B *b) {
+ return dynamic_cast<B *>(b);
+// CHECK: define %struct.B* @_Z8samecastP1B
+// CHECK-NOT: call i8* @__dynamic_cast
+}
diff --git a/clang/test/SemaCXX/no-rtti.cpp b/clang/test/SemaCXX/no-rtti.cpp
index 75167050dca..3d6e109551d 100644
--- a/clang/test/SemaCXX/no-rtti.cpp
+++ b/clang/test/SemaCXX/no-rtti.cpp
@@ -8,3 +8,17 @@ void f()
{
(void)typeid(int); // expected-error {{cannot use typeid with -fno-rtti}}
}
+
+namespace {
+struct A {
+ virtual ~A(){};
+};
+
+struct B : public A {
+ B() : A() {}
+};
+}
+
+bool isa_B(A *a) {
+ return dynamic_cast<B *>(a) != 0; // expected-error {{cannot use dynamic_cast with -fno-rtti}}
+}
OpenPOWER on IntegriCloud