blob: 395c4cbd127b24832ef1ae2fb22e70ff00b5dd13 [file] [log] [blame]
Richard Smith6f4f0f12017-10-20 22:56:25 +00001// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++1z -fsyntax-only -verify
2
3const extern int arr[];
4constexpr auto p = arr; // ok
5constexpr int f(int i) {return p[i];} // expected-note {{read of dereferenced one-past-the-end pointer}}
6
7constexpr int arr[] {1, 2, 3};
8constexpr auto p2 = arr + 2; // ok
9constexpr int x = f(2); // ok
10constexpr int y = f(3); // expected-error {{constant expression}}
11// expected-note-re@-1 {{in call to 'f({{.*}})'}}
12
13// FIXME: consider permitting this case
14struct A {int m[];} a;
15constexpr auto p3 = a.m; // expected-error {{constant expression}} expected-note {{without known bound}}
16constexpr auto p4 = a.m + 1; // expected-error {{constant expression}} expected-note {{without known bound}}
17
18void 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}