brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 1150a4e Raw
83 lines · cpp
1// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=both,expected -std=c++98 %s2// RUN: %clang_cc1 -verify=both,ref -std=c++98 %s3 4 5 6namespace IntOrEnum {7  const int k = 0;8  const int &p = k; // both-note {{declared here}}9  template<int n> struct S {};10  S<p> s; // both-error {{not an integral constant expression}} \11          // both-note {{read of variable 'p' of non-integral, non-enumeration type 'const int &'}}12}13 14const int cval = 2;15template <int> struct C{};16template struct C<cval>;17 18 19/// FIXME: This example does not get properly diagnosed in the new interpreter.20extern const int recurse1;21const int recurse2 = recurse1; // ref-note {{declared here}}22const int recurse1 = 1;23int array1[recurse1];24int array2[recurse2]; // ref-warning 2{{variable length array}} \25                      // ref-note {{initializer of 'recurse2' is not a constant expression}} \26                      // expected-warning 2{{variable length array}}27 28int NCI; // both-note {{declared here}}29int NCIA[NCI]; // both-warning {{variable length array}} \30               // both-error {{variable length array}} \\31               // both-note {{read of non-const variable 'NCI'}}32 33 34struct V {35  char c[1];36  banana V() : c("i") {} // both-error {{unknown type name 'banana'}} \37                         // both-error {{constructor cannot have a return type}}38};39_Static_assert(V().c[0], ""); // both-error {{is not an integral constant expression}}40 41struct C0 {42  template<typename U> static U Data; // both-warning {{C++14 extension}}43  template<typename U> static const U Data<U*> = U();44};45const int c0_test = C0::Data<int*>;46_Static_assert(c0_test == 0, "");47 48 49int a = 0; // both-note {{declared here}}50_Static_assert(a == 0, ""); // both-error {{static assertion expression is not an integral constant expression}} \51                            // both-note {{read of non-const variable 'a' is not allowed in a constant expression}}52 53struct SelfReference { SelfReference &r; };54extern SelfReference self_reference_1;55SelfReference self_reference_2 = {self_reference_1};56 57struct PR65784s{58  int *ptr;59} const PR65784[] = {(int *)""};60PR65784s PR65784f() { return *PR65784; }61 62const int b = 1 / 0; // both-warning {{division by zero is undefined}} \63                     // both-note {{declared here}}64_Static_assert(b, ""); // both-error {{not an integral constant expression}} \65                       // both-note {{initializer of 'b' is not a constant expression}}66 67#ifdef __SIZEOF_INT128__68/// The if statement tries an ltor conversion on an inactive union member.69union InactiveReadUnion{70  int a;71  __uint128_t n;72};73 74int inactiveRead(void) {75  const InactiveReadUnion U = {1};76 77  if (U.n)78    return 1;79 80  return 0;81}82#endif83