brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 5121769 Raw
94 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s2// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -std=gnu++98 %s3// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -std=gnu++11 %s4 5// C++-specific tests for integral constant expressions.6 7const int c = 10;8int ar[c];9 10struct X0 {11  static const int value = static_cast<int>(4.0);12};13 14void f() {15  if (const int value = 17) {16    int array[value];17  }18}19 20int a() {21  const int t=t; // expected-note {{declared here}}22 23  switch(1) { // do not warn that 1 is not a case value;24              // 't' might have been expected to evalaute to 125    case t:; // expected-note {{initializer of 't' is not a constant expression}}26#if __cplusplus <= 199711L27    // expected-error@-2 {{not an integral constant expression}}28#else29    // expected-error@-4 {{case value is not a constant expression}}30#endif31  }32}33 34// PR6206:  out-of-line definitions are legit35namespace pr6206 {36  class Foo {37  public:38    static const int kBar;39  };40 41  const int Foo::kBar = 20;42 43  char Test() {44    char str[Foo::kBar];45    str[0] = '0';46    return str[0];47  }48}49 50// PR6373:  default arguments don't count.51void pr6373(const unsigned x = 0) {52  unsigned max = 80 / x;53}54 55 56namespace rdar9204520 {57 58struct A {59  static const int B = int(0.75 * 1000 * 1000);60#if __cplusplus <= 199711L61  // expected-warning@-2 {{not a constant expression; folding it to a constant is a GNU extension}}62#endif63};64 65int foo() { return A::B; }66}67 68// PR1104069const int x = 10;70int* y = reinterpret_cast<const char&>(x); // expected-error {{cannot initialize}}71 72// This isn't an integral constant expression, but make sure it folds anyway.73struct PR8836 { char _; long long a; };74#if __cplusplus <= 199711L75// expected-warning@-2 {{'long long' is a C++11 extension}}76#endif77 78int PR8836test[(__typeof(sizeof(int)))&reinterpret_cast<const volatile char&>((((PR8836*)0)->a))];79// expected-warning@-1 0-1{{variable length arrays in C++ are a Clang extension}} expected-warning@-1 {{folded to constant array as an extension}}80// expected-note@-2 {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}81 82const int nonconst = 1.0;83#if __cplusplus <= 199711L84// expected-note@-2 {{declared here}}85#endif86int arr[nonconst];87#if __cplusplus <= 199711L88// expected-warning@-2 0-1{{variable length arrays in C++ are a Clang extension}} expected-warning@-2 {{folded to constant array as an extension}}89// expected-note@-3 {{initializer of 'nonconst' is not a constant expression}}90#endif91 92const int castfloat = static_cast<int>(1.0);93int arr2[castfloat]; // ok94