3

In trying to build boost mirror with gcc 4.7.2, I ran into this error, but oddly enough, I see this documentation.

Has ::std::has_nothrow_default_constructor been moved/changed?

In file included from /home/kfeng/src/mirror-lib/include/mirror/type_traits.hpp:20:0,
                 from /home/kfeng/src/mirror-lib/include/mirror/mirror_base.hpp:38,
                 from /home/kfeng/src/mirror-lib/include/mirror/mirror.hpp:16,
                 from /home/kfeng/src/mirror-lib/src/mirror/example/all_member_variables.cpp:10:
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:2: error: ‘has_nothrow_default_constructor’ is not a member of ‘std’
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:28:9: error: parse error in template argument list
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:43: error: expected ‘{’ before ‘::’ token
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:51: error: expected initializer before ‘||’ token
In file included from /home/kfeng/src/mirror-lib/include/mirror/type_traits.hpp:21:0,
                 from /home/kfeng/src/mirror-lib/include/mirror/mirror_base.hpp:38,
                 from /home/kfeng/src/mirror-lib/include/mirror/mirror.hpp:16,
                 from /home/kfeng/src/mirror-lib/src/mirror/example/all_member_variables.cpp:10:
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:2: error: ‘has_nothrow_copy_constructor’ is not a member of ‘std’
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:28:9: error: parse error in template argument list
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:40: error: expected ‘{’ before ‘::’ token
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:48: error: expected initializer before ‘||’ token
make[2]: *** [src/mirror/example/CMakeFiles/mirror-all_member_variables.dir/all_member_variables.cpp.o] Error 1
make[1]: *** [src/mirror/example/CMakeFiles/mirror-all_member_variables.dir/all] Error 2
make: *** [all] Error 2

ANSWER using Pubby's Note Below

Something like this should work with gcc 4.7.2 - I will submit a patch and let the maintainer decide how best to deal with it.

template <typename T>
 struct is_default_constructible
  : std::integral_constant<
        bool,
        ::std::has_trivial_default_constructor<T>::value ||
#if __cplusplus>=201103L 
        ::std::is_nothrow_default_constructible<T>::value ||
#else
        ::std::has_nothrow_default_constructor<T>::value ||
#endif
        mirror::_class::_<T>::has_default_ctr::value>
 { };
kfmfe04
  • 14,936
  • 14
  • 74
  • 140

2 Answers2

6

In C++11 it was changed to std::is_nothrow_default_constructible to be more consistent with naming.

Pubby
  • 51,882
  • 13
  • 139
  • 180
  • +1 tyvm - I will edit the code and try it out - quick aside, there must be an `#ifdef` I can use to check if `--std=c++11` has been passed in... ...gonna google for it – kfmfe04 Dec 17 '12 at 06:50
  • @kfmfe04 You could just use `boost::has_nothrow_default_constructor` – Pubby Dec 17 '12 at 07:05
  • @kfmfe04 Also, `__cplusplus` is the macro you can check, although it might not guarantee that the trait is there. – Pubby Dec 17 '12 at 07:06
1

You are looking at documentation for GCC 4.6.2, but using GCC 4.7.2, so it's not very surprising they don't match.

The traits were renamed by n3142

See a previous answer of mine https://stackoverflow.com/a/12716778/981959 for some code that attempts to detect which is supported by your compiler, although a comment says it doesn't work with libc++.

Community
  • 1
  • 1
Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521