diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 20:41:34 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 20:41:34 +0000 |
commit | da429b901af02d580d5ad602c484d57d75be3f24 (patch) | |
tree | 8182aa751fc7bd56beb57c5be571a2f0598b0cdc /base | |
parent | 9e0b9c2c640c7b62fc4d7fa03b48d3645742ee0f (diff) | |
download | chromium_src-da429b901af02d580d5ad602c484d57d75be3f24.zip chromium_src-da429b901af02d580d5ad602c484d57d75be3f24.tar.gz chromium_src-da429b901af02d580d5ad602c484d57d75be3f24.tar.bz2 |
Use static_cast in LinkNode<T>::value() so that it works with
multiple inheritance.
R=eroman
BUG=none
TEST=LinkedList.MultipleInheritanceNode
Review URL: http://codereview.chromium.org/266020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28439 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/linked_list.h | 4 | ||||
-rw-r--r-- | base/linked_list_unittest.cc | 18 |
2 files changed, 19 insertions, 3 deletions
diff --git a/base/linked_list.h b/base/linked_list.h index ab77a96e..5b5184f 100644 --- a/base/linked_list.h +++ b/base/linked_list.h @@ -118,11 +118,11 @@ class LinkNode { // Cast from the node-type to the value type. const T* value() const { - return reinterpret_cast<const T*>(this); + return static_cast<const T*>(this); } T* value() { - return reinterpret_cast<T*>(this); + return static_cast<T*>(this); } private: diff --git a/base/linked_list_unittest.cc b/base/linked_list_unittest.cc index 835d927..367564c 100644 --- a/base/linked_list_unittest.cc +++ b/base/linked_list_unittest.cc @@ -19,6 +19,18 @@ class Node : public LinkNode<Node> { int id_; }; +class MultipleInheritanceNodeBase { + public: + MultipleInheritanceNodeBase() : field_taking_up_space_(0) {} + int field_taking_up_space_; +}; + +class MultipleInheritanceNode : public MultipleInheritanceNodeBase, + public LinkNode<MultipleInheritanceNode> { + public: + MultipleInheritanceNode() {} +}; + // Checks that when iterating |list| (either from head to tail, or from // tail to head, as determined by |forward|), we get back |node_ids|, // which is an array of size |num_nodes|. @@ -56,7 +68,6 @@ TEST(LinkedList, Empty) { ExpectListContents(list, 0, NULL); } - TEST(LinkedList, Append) { LinkedList<Node> list; ExpectListContents(list, 0, NULL); @@ -241,5 +252,10 @@ TEST(LinkedList, InsertAfter) { } } +TEST(LinkedList, MultipleInheritanceNode) { + MultipleInheritanceNode node; + EXPECT_EQ(&node, node.value()); +} + } // namespace } // namespace base |