summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/constant-expression-cxx11.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/SemaCXX/constant-expression-cxx11.cpp')
-rw-r--r--clang/test/SemaCXX/constant-expression-cxx11.cpp35
1 files changed, 23 insertions, 12 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index e64f2d5a335..68b82c7d96f 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -604,20 +604,31 @@ static_assert(NATDCArray{}[1][1].n == 0, "");
}
-// Tests for indexes into arrays of unknown bounds.
+// Per current CWG direction, we reject any cases where pointer arithmetic is
+// not statically known to be valid.
namespace ArrayOfUnknownBound {
- // This is a corner case of the language where it's not clear whether this
- // should be an error: When we see the initializer for Z::a, the bounds of
- // Z::b aren't known yet, but they will be known by the end of the translation
- // unit, so the compiler can in theory check the indexing into Z::b.
- // For the time being, as long as this is unclear, we want to make sure that
- // this compiles.
- struct Z {
- static const void *const a[];
- static const void *const b[];
+ extern int arr[];
+ constexpr int *a = arr;
+ constexpr int *b = &arr[0];
+ static_assert(a == b, "");
+ constexpr int *c = &arr[1]; // expected-error {{constant}} expected-note {{indexing of array without known bound}}
+ constexpr int *d = &a[1]; // expected-error {{constant}} expected-note {{indexing of array without known bound}}
+ constexpr int *e = a + 1; // expected-error {{constant}} expected-note {{indexing of array without known bound}}
+
+ struct X {
+ int a;
+ int b[]; // expected-warning {{C99}}
};
- constexpr const void *Z::a[] = {&b[0], &b[1]};
- constexpr const void *Z::b[] = {&a[0], &a[1]};
+ extern X x;
+ constexpr int *xb = x.b; // expected-error {{constant}} expected-note {{not supported}}
+
+ struct Y { int a; };
+ extern Y yarr[];
+ constexpr Y *p = yarr;
+ constexpr int *q = &p->a;
+
+ extern const int carr[]; // expected-note {{here}}
+ constexpr int n = carr[0]; // expected-error {{constant}} expected-note {{non-constexpr variable}}
}
namespace DependentValues {
OpenPOWER on IntegriCloud