diff options
Diffstat (limited to 'clang/test/AST/ByteCode/arrays.cpp')
-rw-r--r-- | clang/test/AST/ByteCode/arrays.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/arrays.cpp b/clang/test/AST/ByteCode/arrays.cpp index 2dd51c2..8ef5e4d 100644 --- a/clang/test/AST/ByteCode/arrays.cpp +++ b/clang/test/AST/ByteCode/arrays.cpp @@ -779,3 +779,20 @@ namespace DiscardedSubScriptExpr { return true; } } + +namespace ZeroSizeArrayRead { + constexpr char str[0] = {}; + constexpr unsigned checksum(const char *s) { + unsigned result = 0; + for (const char *p = s; *p != '\0'; ++p) { // both-note {{read of dereferenced one-past-the-end pointer}} + result += *p; + } + return result; + } + constexpr unsigned C = checksum(str); // both-error {{must be initialized by a constant expression}} \ + // both-note {{in call to}} + + constexpr const char *p1 = &str[0]; + constexpr const char *p2 = &str[1]; // both-error {{must be initialized by a constant expression}} \ + // both-note {{cannot refer to element 1 of array of 0 elements in a constant expression}} +} |