diff options
author | Paul Pogonyshev <pogonyshev@gmx.net> | 2005-06-12 21:10:41 +0000 |
---|---|---|
committer | Murray Cumming <murrayc@src.gnome.org> | 2005-06-12 21:10:41 +0000 |
commit | d21a488fa42f7937b1a7719d81f2643df4a51cf8 (patch) | |
tree | 42560aada072116fad552c6b9d4d6fc6e226e6bc | |
parent | 141af712fa962204a7c24ba6c72e0030cc396a8b (diff) | |
download | sigc++-d21a488fa42f7937b1a7719d81f2643df4a51cf8.tar.gz |
Add test for whether the compiler allows referencing to member functions
2005-06-12 Paul Pogonyshev <pogonyshev@gmx.net>
* configure.ac:
* scripts/cxx.m4:
* sigc++config.h.in: Add test for whether the compiler allows
referencing to member functions of the class/structure being
declared from a definition of a static member variable.
Supposedly a generic solution for GCC 3.2 compilation problems.
* sigc++/type_traits.h: Define SIGC_WRAP_IS_BASE_CLASS_ based on
results of the above test.
(struct is_base_and_derived): Wrap up is_base_class_() functions
in an internal class if SIGC_WRAP_IS_BASE_CLASS_ is defined.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | scripts/cxx.m4 | 27 | ||||
-rw-r--r-- | sigc++/type_traits.h | 37 | ||||
-rw-r--r-- | sigc++config.h.in | 3 |
5 files changed, 70 insertions, 12 deletions
@@ -1,3 +1,17 @@ +2005-06-12 Paul Pogonyshev <pogonyshev@gmx.net> + + * configure.ac: + * scripts/cxx.m4: + * sigc++config.h.in: Add test for whether the compiler allows + referencing to member functions of the class/structure being + declared from a definition of a static member variable. + Supposedly a generic solution for GCC 3.2 compilation problems. + + * sigc++/type_traits.h: Define SIGC_WRAP_IS_BASE_CLASS_ based on + results of the above test. + (struct is_base_and_derived): Wrap up is_base_class_() functions + in an internal class if SIGC_WRAP_IS_BASE_CLASS_ is defined. + 2005-06-10 Murray Cumming <murrayc@murrayc.com> * sigc++/adaptors/macros/bind.h.m4: diff --git a/configure.ac b/configure.ac index 6359f5c..e0fcfaf 100644 --- a/configure.ac +++ b/configure.ac @@ -101,6 +101,7 @@ AC_LANG_CPLUSPLUS SIGC_CXX_GCC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD() SIGC_CXX_MSVC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD() +SIGC_CXX_SELF_REFERENCE_IN_MEMBER_INITIALIZATION() SIGC_CXX_HAS_NAMESPACE_STD() SIGC_CXX_HAS_SUN_REVERSE_ITERATOR() diff --git a/scripts/cxx.m4 b/scripts/cxx.m4 index 0002a4c..11f1969 100644 --- a/scripts/cxx.m4 +++ b/scripts/cxx.m4 @@ -93,3 +93,30 @@ AC_TRY_COMPILE( AC_MSG_RESULT([$sigcm_cxx_msvc_template_specialization_operator_overload]) ]) ]) + + +AC_DEFUN([SIGC_CXX_SELF_REFERENCE_IN_MEMBER_INITIALIZATION], [ +AC_MSG_CHECKING([if C++ compiler allows usage of member function in initialization of static member field.]) +AC_TRY_COMPILE( +[ + struct test + { + static char test_function(); + + // Doesn't work with e.g. GCC 3.2. However, if test_function() + // is wrapped in a nested structure, it works just fine. + static const bool test_value + = (sizeof(test_function()) == sizeof(char)); + }; +], +[], +[ + sigcm_cxx_self_reference_in_member_initialization=yes + AC_DEFINE([SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION],[1], + [does c++ compiler allows usage of member function in initialization of static member field.]) + AC_MSG_RESULT([$sigcm_cxx_self_reference_in_member_initialization]) +],[ + sigcm_cxx_self_reference_in_member_initialization=no + AC_MSG_RESULT([$sigcm_cxx_self_reference_in_member_initialization]) +]) +]) diff --git a/sigc++/type_traits.h b/sigc++/type_traits.h index dee53ca..56b27a9 100644 --- a/sigc++/type_traits.h +++ b/sigc++/type_traits.h @@ -19,6 +19,9 @@ #ifndef _SIGC_TYPE_TRAIT_H_ #define _SIGC_TYPE_TRAIT_H_ +#include <sigc++config.h> //To get SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION + + namespace sigc { template <class T_type> @@ -97,27 +100,39 @@ private: char memory[64]; }; - //Allow the test inner class to access the other (big) inner class. - //The Tru64 compiler needs this. murrayc. - //struct test; - //friend struct test; +#ifndef SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION - //The AIX xlC compiler does not like these 2 functions being in the inner class. - //It says "The incomplete type "test" must no be used as a qualifier. - //It does not seem necessary anyway. murrayc. + //Allow the internal inner class to access the other (big) inner + //class. The Tru64 compiler needs this. murrayc. + friend struct internal; - //struct test { - //For gcc 3.2, try uncommenting the "struct test" inner class declaration, and also using a test:: prefix below. - //If it works then submit a patch. A new configure-time compiler-ability check would be even better. murrayc. + //Certain compilers, notably GCC 3.2, require these functions to be inside an inner class. + struct internal + { static big is_base_class_(...); static char is_base_class_(typename type_trait<T_base>::pointer); - //}; + }; + +public: + static const bool value = + sizeof(internal::is_base_class_(reinterpret_cast<typename type_trait<T_derived>::pointer>(0))) == + sizeof(char); + +#else //SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION + + //The AIX xlC compiler does not like these 2 functions being in the inner class. + //It says "The incomplete type "test" must not be used as a qualifier. + //It does not seem necessary anyway. murrayc. + static big is_base_class_(...); + static char is_base_class_(typename type_trait<T_base>::pointer); public: static const bool value = sizeof(is_base_class_(reinterpret_cast<typename type_trait<T_derived>::pointer>(0))) == sizeof(char); +#endif //SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION + void avoid_gcc3_warning_(); //Not implemented. g++ 3.3.5 (but not 3.3.4, and not 3.4) warn that there are no public methods, even though there is a public variable. }; diff --git a/sigc++config.h.in b/sigc++config.h.in index a570b5f..1cd8c3e 100644 --- a/sigc++config.h.in +++ b/sigc++config.h.in @@ -26,7 +26,8 @@ // configure checks #undef SIGC_GCC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD #undef SIGC_MSVC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD - + #undef SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION + #undef SIGC_HAVE_NAMESPACE_STD #undef SIGC_HAVE_SUN_REVERSE_ITERATOR #undef SIGC_TYPEDEF_REDEFINE_ALLOWED |