util_static_assert.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2011-2016 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __UTIL_STATIC_ASSERT_H__
  17. # define __UTIL_STATIC_ASSERT_H__
  18. CCL_NAMESPACE_BEGIN
  19. /* TODO(sergey): In theory CUDA might work with own static assert
  20. * implementation since it's just pure C++.
  21. */
  22. # ifdef __KERNEL_GPU__
  23. # ifndef static_assert
  24. # define static_assert(statement, message)
  25. # endif
  26. # endif /* __KERNEL_GPU__ */
  27. /* TODO(sergey): For until C++11 is a bare minimum for us,
  28. * we do a bit of a trickery to show meaningful message so
  29. * it's more or less clear what's wrong when building without
  30. * C++11.
  31. *
  32. * The thing here is: our non-C++11 implementation doesn't
  33. * have a way to print any message after preprocessor
  34. * substitution so we rely on the message which is passed to
  35. * static_assert() since that's the only message visible when
  36. * compilation fails.
  37. *
  38. * After C++11 bump it should be possible to glue structure
  39. * name to the error message,
  40. */
  41. # define static_assert_align(st, align) \
  42. static_assert((sizeof(st) % (align) == 0), "Structure must be strictly aligned") // NOLINT
  43. CCL_NAMESPACE_END
  44. #endif /* __UTIL_STATIC_ASSERT_H__ */