compiler_ut.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "compiler.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. Y_UNIT_TEST_SUITE(TCompilerTest) {
  4. Y_UNIT_TEST(TestPragmaNoWshadow) {
  5. Y_PRAGMA_DIAGNOSTIC_PUSH
  6. Y_PRAGMA_NO_WSHADOW
  7. // define two variables with similar names, latest must shadow first
  8. // and there will be no warning for this
  9. for (int i = 0; i < 1; ++i) {
  10. for (int i = 100500; i < 100501; ++i) {
  11. UNIT_ASSERT_EQUAL(i, 100500);
  12. }
  13. }
  14. Y_PRAGMA_DIAGNOSTIC_POP
  15. }
  16. Y_PRAGMA_DIAGNOSTIC_PUSH
  17. Y_PRAGMA_NO_UNUSED_PARAMETER
  18. // define function with unused named parameter
  19. // and there will be no warning for this
  20. int Foo(int a) {
  21. return 0;
  22. }
  23. Y_PRAGMA_DIAGNOSTIC_POP
  24. Y_UNIT_TEST(TestPragmaNoUnusedParameter) {
  25. UNIT_ASSERT_EQUAL(Foo(1), 0);
  26. }
  27. Y_UNIT_TEST(TestHaveInt128) {
  28. #ifdef Y_HAVE_INT128
  29. // will be compiled without errors
  30. unsigned __int128 a = 1;
  31. __int128 b = 1;
  32. UNIT_ASSERT_EQUAL(a, 1);
  33. UNIT_ASSERT_EQUAL(b, 1);
  34. UNIT_ASSERT_EQUAL(sizeof(a), sizeof(b));
  35. // and we can set a type alias for __int128 and unsigned __int128 without compiler errors
  36. using TMyInt128 = __int128;
  37. using TMyUnsignedInt128 = unsigned __int128;
  38. TMyInt128 i128value;
  39. TMyUnsignedInt128 ui128value;
  40. Y_UNUSED(i128value);
  41. Y_UNUSED(ui128value);
  42. #endif
  43. }
  44. // define deprecated function
  45. [[deprecated]] void Bar() {
  46. return;
  47. }
  48. Y_UNIT_TEST(TestNoDeprecated) {
  49. Y_PRAGMA_DIAGNOSTIC_PUSH
  50. Y_PRAGMA_NO_DEPRECATED
  51. // will be compiled without errors
  52. Bar();
  53. Y_PRAGMA_DIAGNOSTIC_POP
  54. }
  55. } // Y_UNIT_TEST_SUITE(TCompilerTest)