From e26feaa806e534b17e2dc9336cf73049408149d4 Mon Sep 17 00:00:00 2001 From: Davis King Date: Fri, 31 Oct 2008 12:46:56 +0000 Subject: [PATCH] Removed dangerous implicit casts between unrelated member function pointer types. Also made the spec more clear. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402619 --- .../member_function_pointer_kernel_1.h | 15 ++++++++++----- .../member_function_pointer_kernel_abstract.h | 7 +++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dlib/member_function_pointer/member_function_pointer_kernel_1.h b/dlib/member_function_pointer/member_function_pointer_kernel_1.h index 0190d7482..d4972a976 100644 --- a/dlib/member_function_pointer/member_function_pointer_kernel_1.h +++ b/dlib/member_function_pointer/member_function_pointer_kernel_1.h @@ -23,11 +23,16 @@ namespace dlib // ---------------------------------------------------------------------------------------- + template class mfp_kernel_1_base_class { /* All member function pointer classes inherit from this class. This is where most of the things in a member function pointer are defined. + + The reason for the num_args template argument to this class is to prevent + any sort of implicit casting between derived member function pointer classes + that take different numbers of arguments. */ protected: enum mfp_type { mfp_nonconst, mfp_const, mfp_null}; @@ -165,7 +170,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- template <> - class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class + class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class<0> { class mp_base : public mp_base_base { public: @@ -224,7 +229,7 @@ namespace dlib template < typename PARAM1 > - class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class + class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class<1> { class mp_base : public mp_base_base { public: @@ -284,7 +289,7 @@ namespace dlib typename PARAM1, typename PARAM2 > - class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class + class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class<2> { class mp_base : public mp_base_base { public: @@ -345,7 +350,7 @@ namespace dlib typename PARAM2, typename PARAM3 > - class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class + class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class<3> { class mp_base : public mp_base_base { public: @@ -407,7 +412,7 @@ namespace dlib typename PARAM3, typename PARAM4 > - class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class + class member_function_pointer_kernel_1 : public mfp_kernel_1_base_class<4> { class mp_base : public mp_base_base { public: diff --git a/dlib/member_function_pointer/member_function_pointer_kernel_abstract.h b/dlib/member_function_pointer/member_function_pointer_kernel_abstract.h index 8d10bc223..336883285 100644 --- a/dlib/member_function_pointer/member_function_pointer_kernel_abstract.h +++ b/dlib/member_function_pointer/member_function_pointer_kernel_abstract.h @@ -167,11 +167,14 @@ namespace dlib If this exception is thrown then #is_set() == false !*/ - operator bool ( + operator some_undefined_pointer_type ( ) const; /*! ensures - - returns is_set() + - if (is_set()) then + - returns a non 0 value + - else + - returns a 0 value !*/ bool operator! (