[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH 2/3] + C++ ABI: pure virtual functions
---
STATUS | 2 +-
include/cxxabi.h | 28 ++++++++++++++++++
include/lightlibc++/doxygen.hpp | 2 +
source/cxxabi/pure_virtual.cpp | 32 +++++++++++++++++++++
testcase/cxxabi/pure_virtual.cpp | 57 ++++++++++++++++++++++++++++++++++++++
testcase/cxxabi/pure_virtual.sh | 10 ++++++
6 files changed, 130 insertions(+), 1 deletions(-)
create mode 100644 source/cxxabi/pure_virtual.cpp
create mode 100644 testcase/cxxabi/pure_virtual.cpp
create mode 100755 testcase/cxxabi/pure_virtual.sh
diff --git a/STATUS b/STATUS
index f5b891d..d32ca9a 100644
--- a/STATUS
+++ b/STATUS
@@ -98,7 +98,7 @@ This file documents the status of the implementation.
C++ Application Binary Interface (Itanium C++ ABI)
* RTTI (2.9.5) [X]
* dynamic_cast (2.9.7) [ ]
-* Pure virtual functions (3.2.6) [ ]
+* Pure virtual functions (3.2.6) [X]
* One-time construction (3.3.2) [ ]
* Array construction and destruction (3.3.3) [ ]
* Controlling object construction order (3.3.4) [ ]
diff --git a/include/cxxabi.h b/include/cxxabi.h
index 0449f63..bad7ea3 100644
--- a/include/cxxabi.h
+++ b/include/cxxabi.h
@@ -20,6 +20,7 @@ this is not to use the software at all.
#include <typeinfo> // std::type_info
+#include <lightlibc++/compiler.hpp>
@@ -456,6 +457,33 @@ namespace abi
{
// Lift all classes from __cxxabiv1 to the abi namespace
using namespace __cxxabiv1;
+
+
+
+ /** \addtogroup lightlibcpp_cxxabi_pure_virtual */
+ /*@{*/
+
+ extern "C"
+ {
+ /**
+ *\english
+ * This function is called at runtime if a pure virtual function is being
+ * called not overwritten by any derived class.
+ *
+ * __cxa_pure_virtual() does not return to the caller.
+ *\endenglish
+ *\german
+ * Diese Funktion wird zur Laufzeit aufgerufen, falls eine rein-virtuelle
+ * Funktion zum Zeitpunkt des Aufrufs von keiner abgeleiteten Klasse
+ * überschrieben wird.
+ *
+ * __cxa_pure_virtual() kehrt nicht zum Aufrufenden zurück.
+ *\endgerman
+ */
+ void __cxa_pure_virtual() _LIGHTLIBCPP_NORETURN;
+ }
+
+ /*@}*/
}
diff --git a/include/lightlibc++/doxygen.hpp b/include/lightlibc++/doxygen.hpp
index bbbfe46..e052fc3 100644
--- a/include/lightlibc++/doxygen.hpp
+++ b/include/lightlibc++/doxygen.hpp
@@ -42,3 +42,5 @@ this is not to use the software at all.
/** \defgroup lightlibcpp_cxxabi C++ Application Binary Interface */
/** \defgroup lightlibcpp_cxxabi_rtti RTTI (= Runtime Type Information)
* \ingroup lightlibcpp_cxxabi */
+/** \defgroup lightlibcpp_cxxabi_pure_virtual pure virtual functions
+ * \ingroup lightlibcpp_cxxabi */
diff --git a/source/cxxabi/pure_virtual.cpp b/source/cxxabi/pure_virtual.cpp
new file mode 100644
index 0000000..2faa36d
--- /dev/null
+++ b/source/cxxabi/pure_virtual.cpp
@@ -0,0 +1,32 @@
+/*
+Permission is granted to use, modify, and / or redistribute at will.
+
+This includes removing authorship notices, re-use of code parts in
+other software (with or without giving credit), and / or creating a
+commercial product based on it.
+
+This permission is not revocable by the author.
+
+This software is provided as-is. Use it at your own risk. There is
+no warranty whatsoever, neither expressed nor implied, and by using
+this software you accept that the author(s) shall not be held liable
+for any loss of data, loss of service, or other damages, be they
+incidental or consequential. Your only option other than accepting
+this is not to use the software at all.
+*/
+#include <cxxabi.h>
+// TODO #include <cstdio>
+#include <stdio.h> // fprintf, stderr
+#include <exception> // std::terminate
+
+
+
+/*
+ * functions
+ */
+
+void abi::__cxa_pure_virtual()
+{
+ fprintf(stderr, "Error: Pure virtual function called\n");
+ std::terminate();
+}
diff --git a/testcase/cxxabi/pure_virtual.cpp b/testcase/cxxabi/pure_virtual.cpp
new file mode 100644
index 0000000..e9a924d
--- /dev/null
+++ b/testcase/cxxabi/pure_virtual.cpp
@@ -0,0 +1,57 @@
+/*
+Permission is granted to use, modify, and / or redistribute at will.
+
+This includes removing authorship notices, re-use of code parts in
+other software (with or without giving credit), and / or creating a
+commercial product based on it.
+
+This permission is not revocable by the author.
+
+This software is provided as-is. Use it at your own risk. There is
+no warranty whatsoever, neither expressed nor implied, and by using
+this software you accept that the author(s) shall not be held liable
+for any loss of data, loss of service, or other damages, be they
+incidental or consequential. Your only option other than accepting
+this is not to use the software at all.
+*/
+#include <cstdlib>
+
+/*
+ * NOTE: This testcase is supposed to fail during execution
+ * This testcase checks that a handler for pure virtual functions that are
+ * not properly set is called
+ */
+
+class base
+{
+ public:
+ base()
+ {
+ // f1 calls our pure virtual function,
+ // but derived is not yet constructed
+ f1();
+ }
+
+ void f1()
+ {
+ f2();
+ }
+
+ virtual void f2() = 0;
+ virtual ~base(){}
+};
+
+class derived : public base
+{
+ public:
+ virtual void f2()
+ {
+ }
+};
+
+int main()
+{
+ derived* d = new derived();
+ d->f2();
+ return EXIT_SUCCESS;
+}
diff --git a/testcase/cxxabi/pure_virtual.sh b/testcase/cxxabi/pure_virtual.sh
new file mode 100755
index 0000000..f4c1c8a
--- /dev/null
+++ b/testcase/cxxabi/pure_virtual.sh
@@ -0,0 +1,10 @@
+#! /bin/bash
+
+./testcase/cxxabi/pure_virtual
+
+if [ $? == 0 ]
+then
+ exit 1
+fi
+
+exit 0
--
1.6.0.4