1 | // RUN: %clang_cc1 %s -Wno-uninitialized -std=c++1z -fsyntax-only -verify |
2 | |
3 | const extern int arr[]; |
4 | constexpr auto p = arr; // ok |
5 | constexpr int f(int i) {return p[i];} // expected-note {{read of dereferenced one-past-the-end pointer}} |
6 | |
7 | constexpr int arr[] {1, 2, 3}; |
8 | constexpr auto p2 = arr + 2; // ok |
9 | constexpr int x = f(2); // ok |
10 | constexpr int y = f(3); // expected-error {{constant expression}} |
11 | // expected-note-re@-1 {{in call to 'f({{.*}})'}} |
12 | |
13 | // FIXME: consider permitting this case |
14 | struct A {int m[];} a; |
15 | constexpr auto p3 = a.m; // expected-error {{constant expression}} expected-note {{without known bound}} |
16 | constexpr auto p4 = a.m + 1; // expected-error {{constant expression}} expected-note {{without known bound}} |
17 | |
18 | void g(int i) { |
19 | int arr[i]; |
20 | constexpr auto *p = arr + 2; // expected-error {{constant expression}} expected-note {{without known bound}} |
21 | |
22 | // FIXME: Give a better diagnostic here. The issue is that computing |
23 | // sizeof(*arr2) within the array indexing fails due to the VLA. |
24 | int arr2[2][i]; |
25 | constexpr int m = ((void)arr2[2], 0); // expected-error {{constant expression}} |
26 | } |
27 | |