brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 5237d75 Raw
86 lines · cpp
1// RUN: %clang_cc1 %s -fsyntax-only -ffixed-point -verify=expected,both -fexperimental-new-constant-interpreter2// RUN: %clang_cc1 %s -fsyntax-only -ffixed-point -verify=ref,both3 4static_assert((bool)1.0k);5static_assert(!((bool)0.0k));6static_assert((bool)0.0k); // both-error {{static assertion failed}}7 8static_assert(1.0k == 1.0k);9static_assert(1.0k == 1);10static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k != 1.0k'}}11static_assert(1.0k != 1); // both-error {{failed due to requirement '1.0k != 1'}}12static_assert(-12.0k == -(-(-12.0k)));13 14constexpr _Accum acc = (0.5r, 6.9k);15 16/// Zero-init.17constexpr _Accum A{};18static_assert(A == 0.0k);19static_assert(A == 0);20static_assert(!A);21 22constexpr bool toBool() {23  if (A)24    return true;25  return false;26}27static_assert(!toBool());28 29namespace IntToFixedPointCast {30  constexpr _Accum B = 13;31  static_assert(B == 13.0k);32  static_assert(B == 13);33 34  constexpr _Fract sf = -1;35  static_assert(sf == -1.0k);36  static_assert(sf == -1);37}38 39namespace FixedPointToIntCasts {40  constexpr _Accum A = -13.0k;41  constexpr int I = A;42  static_assert(I == -13);43}44 45namespace FloatToFixedPointCast {46  constexpr _Fract sf = 1.0; // both-error {{must be initialized by a constant expression}} \47                             // both-note {{outside the range of representable values of type 'const _Fract'}}48 49  constexpr _Fract sf2 = 0.5;50  static_assert(sf2 == 0.5);51  constexpr float sf2f = sf2;52  static_assert(sf2f == 0.5);53}54 55namespace BinOps {56  constexpr _Accum A = 13;57  static_assert(A + 1 == 14.0k);58  static_assert(1 + A == 14.0k);59  static_assert((A + A) == 26);60 61  static_assert(A + 100000 == 14.0k); // both-error {{is not an integral constant expression}} \62                                      // both-note {{is outside the range of representable values}}63 64  static_assert((A - A) == 0);65  constexpr short _Accum mul_ovf1 = 255.0hk * 4.5hk; // both-error {{must be initialized by a constant expression}} \66                                                     // both-note {{value 123.5 is outside the range of representable values of type 'short _Accum'}}67  constexpr short _Accum div_ovf1 = 255.0hk / 0.5hk; // both-error {{must be initialized by a constant expression}} \68                                                     // both-note {{value -2.0 is outside the range of representable values of type 'short _Accum'}}69 70}71 72namespace FixedPointCasts {73  constexpr _Fract B = 0.3;74  constexpr _Accum A = B;75  constexpr _Fract C = A;76}77 78namespace Cmp {79  constexpr _Accum A = 13.0k;80  constexpr _Accum B = 14.0k;81  static_assert(B > A);82  static_assert(B >= A);83  static_assert(A < B);84  static_assert(A <= B);85}86