static_assert_test_fail_5.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // (C) Copyright Steve Cleary & John Maddock 2000.
  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. #include <boost/static_assert.hpp>
  7. //
  8. // all these tests should fail:
  9. //
  10. // Template class scope
  11. template <class Int, class Char>
  12. struct Bill
  13. {
  14. private: // can be in private, to avoid namespace pollution
  15. BOOST_STATIC_ASSERT(sizeof(Int) == 4);
  16. BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Char)); // should not compile when instantiated
  17. public:
  18. // Template member function scope: provides access to member variables
  19. Int x;
  20. Char c;
  21. template <class Int2, class Char2>
  22. void f(Int2 , Char2 )
  23. {
  24. BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Int2));
  25. BOOST_STATIC_ASSERT(sizeof(Char) == sizeof(Char2));
  26. //BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Char)); // should not compile when instantiated
  27. }
  28. };
  29. Bill<int, char> b;