~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to clang/test/SemaCXX/cxx1y-array-runtime-bound.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// RUN: %clang_cc1 -std=c++1y %s -verify -triple=x86_64-linux-gnu -pedantic-errors
 
2
 
 
3
// FIXME: many diagnostics here say 'variably modified type'.
 
4
//        catch this case and say 'array of runtime bound' instead.
 
5
 
 
6
namespace std { struct type_info; }
 
7
 
 
8
struct S {
 
9
  int arr[__SIZE_MAX__ / 32];
 
10
};
 
11
S s[32]; // expected-error {{array is too large}}
 
12
 
 
13
int n;
 
14
int a[n]; // expected-error {{not allowed at file scope}}
 
15
 
 
16
struct T {
 
17
  int a[n]; // expected-error {{fields must have a constant size}}
 
18
  static int b[n]; // expected-error {{not allowed at file scope}}
 
19
};
 
20
 
 
21
int g(int n, int a[n]);
 
22
 
 
23
template<typename T> struct X {};
 
24
template<int N, int[N]> struct Y {};
 
25
template<int[n]> struct Z {}; // expected-error {{of variably modified type}}
 
26
 
 
27
int f(int n) {
 
28
  int arb[n]; // expected-note 3{{here}}
 
29
  [arb] {} (); // expected-error {{cannot be captured}}
 
30
 
 
31
  // FIXME: an array of runtime bound can be captured by reference.
 
32
  [&arb] { // expected-error {{cannot be captured}}
 
33
    // Capturing the array implicitly captures the bound, if we need it
 
34
    // in a range-based for loop.
 
35
    for (auto &n : arb) { } // expected-error {{cannot be captured}}
 
36
  } ();
 
37
 
 
38
  X<int[n]> x; // expected-error {{variably modified type}}
 
39
 
 
40
  int arb_neg[-1]; // expected-error {{negative size}}
 
41
  int arb_of_array[n][2];
 
42
  int arr[3] = { 1, 2, 3, 4 }; // expected-error {{excess elements}}
 
43
  char foo[4] = "fool"; // expected-error {{initializer-string for char array is too long}}
 
44
 
 
45
  static int not_auto1[n]; // expected-error {{can not have 'static'}}
 
46
  extern int not_auto2[n]; // expected-error {{can not have 'extern'}}
 
47
  // FIXME: say 'thread_local' not 'static'.
 
48
  thread_local int not_auto1[n]; // expected-error {{can not have 'static'}}
 
49
 
 
50
  // FIXME: these should all be invalid.
 
51
  auto &&ti1 = typeid(arb);
 
52
  auto &&ti2 = typeid(int[n]);
 
53
  auto &&so1 = sizeof(arb);
 
54
  auto &&so2 = sizeof(int[n]);
 
55
  auto *p = &arb;
 
56
  decltype(arb) arb2;
 
57
  int (*arbp)[n] = 0;
 
58
  const int (&arbr)[n] = arbr; // expected-warning {{not yet bound}}
 
59
  typedef int arbty[n];
 
60
  int array_of_arb[2][n];
 
61
 
 
62
  struct Dyn { Dyn() {} Dyn(int) {} ~Dyn() {} };
 
63
 
 
64
  // FIXME: these should be valid.
 
65
  int arb_dynamic[n] = { 1, 2, 3, 4 }; // expected-error {{may not be initialized}}
 
66
  Dyn dyn[n]; // expected-error {{non-POD}}
 
67
  Dyn dyn_init[n] = { 1, 2, 3, 4 }; // expected-error {{non-POD}}
 
68
}