static_assert_test_fail_6.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. void foo()
  30. {
  31. int i = 0;
  32. char c = 0;
  33. Bill<int, char> b;
  34. // this should fail:
  35. b.f(i, c);
  36. }