brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 2b09a1c Raw
29 lines · cpp
1// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++1z -fsyntax-only -verify2 3const extern int arr[];4constexpr auto p = arr; // ok5constexpr 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; // ok9constexpr int x = f(2); // ok10constexpr int y = f(3); // expected-error {{constant expression}}11// expected-note-re@-1 {{in call to 'f({{.*}})'}}12 13// FIXME: consider permitting this case14struct 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) {  // expected-note 2{{declared here}}19  int arr[i]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \20                 expected-note {{function parameter 'i' with unknown value cannot be used in a constant expression}}21  constexpr auto *p = arr + 2; // expected-error {{constant expression}} expected-note {{without known bound}}22 23  // FIXME: Give a better diagnostic here. The issue is that computing24  // sizeof(*arr2) within the array indexing fails due to the VLA.25  int arr2[2][i]; // expected-warning 2{{variable length arrays in C++ are a Clang extension}} \26                     expected-note {{function parameter 'i' with unknown value cannot be used in a constant expression}}27  constexpr int m = ((void)arr2[2], 0); // expected-error {{constant expression}}28}29