From 3dfac48dea1779085f03c670d96856a465aa0b83 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 26 Apr 2015 05:07:44 +0200 Subject: [PATCH] verify actual memory locations - all those casts must refer to the same memory location - but building a new object needs to create a different address --- tests/library/meta/access-casted-test.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/library/meta/access-casted-test.cpp b/tests/library/meta/access-casted-test.cpp index 391cb3c49..a845af838 100644 --- a/tests/library/meta/access-casted-test.cpp +++ b/tests/library/meta/access-casted-test.cpp @@ -25,6 +25,7 @@ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" #include "lib/access-casted.hpp" +#include "lib/util.hpp" #include #include @@ -36,6 +37,8 @@ using std::ostream; using std::cout; using std::endl; +using util::isSameObject; + using lumiera::error::LUMIERA_ERROR_BOTTOM_VALUE; using lumiera::error::LUMIERA_ERROR_WRONG_TYPE; @@ -58,7 +61,10 @@ namespace test { virtual ~E() {}; }; - struct X {}; + struct X + { + char x = 'x'; + }; struct F : X @@ -225,7 +231,7 @@ namespace test { cout << "Access(E(F)* as F&) --->" << AccessCasted::access(pEF) <" << AccessCasted::access(pEF) <" << AccessCasted::access(pF) <" << AccessCasted::access(pXF) <" << AccessCasted::access(pXF) <" << AccessCasted::access(pF) <::access(pEF); // cross-cast not supported (to complicated to implement) // AccessCasted::access(pXF); // downcast not possible, since X does not provide RTTI @@ -236,6 +242,14 @@ namespace test { cout << "Access(float as long) --->" << AccessCasted::access(fp) <::access(i); // would undermine the type system, thus ruled out // AccessCasted::access(i); // allowed, but warning: returning reference to temporary (and the warning is justified) + + CHECK (isSameObject (d, AccessCasted::access(d))); + CHECK (isSameObject (rD, AccessCasted::access(pD))); + CHECK (isSameObject (d, AccessCasted::access(pD))); + CHECK (!isSameObject (d, AccessCasted::access(rD))); + + CHECK (isSameObject (f, AccessCasted::access(rEF))); + CHECK (!isSameObject (f, AccessCasted::access(pF))); // note: address adjustment due to layout of mixin object X } };