test_static_warning.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // (C) Copyright Jonathan Turkanis 2004.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org for most recent version including documentation.
  6. // note: this is a compile only test.
  7. #include <boost/config.hpp> // BOOST_STATIC_CONST
  8. #include <boost/static_assert.hpp>
  9. #include <boost/type_traits/is_polymorphic.hpp>
  10. #include <boost/serialization/static_warning.hpp>
  11. typedef char a1[2];
  12. typedef char a2[3];
  13. class polymorphic {
  14. virtual ~polymorphic();
  15. };
  16. class non_polymorphic {
  17. };
  18. template<class T>
  19. int f(){
  20. BOOST_STATIC_WARNING(T::value);
  21. return 0;
  22. }
  23. struct A {
  24. BOOST_STATIC_CONSTANT(bool, value = false);
  25. };
  26. /////////////////////////////////////////////////////////////////////////
  27. // compilation of this program should show a total of 10 warning messages
  28. // should show NO warning message
  29. BOOST_STATIC_WARNING(true);
  30. // the following should show 5 warning message
  31. int x = f<A>(); // Warn
  32. int y = f<boost::is_polymorphic<non_polymorphic> >(); // Warn.
  33. int z = f<boost::is_polymorphic<polymorphic> >();
  34. BOOST_STATIC_WARNING(sizeof(a1) == sizeof(a2)); // Warn.
  35. BOOST_STATIC_WARNING(sizeof(a1) != sizeof(a1)); // Warn.
  36. BOOST_STATIC_WARNING(! boost::is_polymorphic<polymorphic>::value); // Warn.
  37. BOOST_STATIC_WARNING(boost::is_polymorphic<non_polymorphic>::value); // Warn.
  38. int main(int /* argc */, char * /* argv */[]){
  39. // should show NO warning message
  40. BOOST_STATIC_WARNING(true);
  41. // the following should show 5 warning message
  42. f<A>();
  43. BOOST_STATIC_WARNING(sizeof(a1) == sizeof(a2)); // Warn.
  44. BOOST_STATIC_WARNING(sizeof(a1) != sizeof(a1)); // Warn.
  45. BOOST_STATIC_WARNING(! boost::is_polymorphic<polymorphic>::value); // Warn.
  46. BOOST_STATIC_WARNING(boost::is_polymorphic<non_polymorphic>::value); // Warn.
  47. return 0;
  48. }