llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> --- Full diff: https://github.com/llvm/llvm-project/pull/237882.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Context.cpp (+8-2) - (modified) clang/test/SemaCXX/static-assert-cxx26.cpp (+12) ``````````diff diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index 5dd73467dfe914..378a1f6f6538b1 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -219,8 +219,14 @@ bool Context::evaluateStringRepr(const EvalSettings &Settings, return false; } - if (!Ptr.isLive() || !Ptr.isInitialized() || Ptr.isUnknownSizeArray() || - !Ptr.inArray()) + if (Ptr.isOnePastEnd()) { + S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_past_end) + << AK_Read; + return false; + } + + if (!Ptr.isLive() || Ptr.isUnknownSizeArray() || !Ptr.inArray() || + !Ptr.isReadablePointerType() || !Ptr.isInitialized()) return false; // Must be char. diff --git a/clang/test/SemaCXX/static-assert-cxx26.cpp b/clang/test/SemaCXX/static-assert-cxx26.cpp index 644805a9e84c7d..043f9dbf189323 100644 --- a/clang/test/SemaCXX/static-assert-cxx26.cpp +++ b/clang/test/SemaCXX/static-assert-cxx26.cpp @@ -426,3 +426,15 @@ namespace DataPtrIsNull { // expected-note {{read of dereferenced null pointer is not allowed in a constant expression}} \ // expected-error {{static assertion failed}} } + +namespace OnePastEndRead { + constexpr const char foo[] = {}; + + struct S { + constexpr int size() const { return 4; } + constexpr const char *data() const { return foo; } + }; + static_assert(false, S{}); // expected-error {{must be produced by a constant expression}} \ + // expected-note {{read of dereferenced one-past-the-end pointer}} \ + // expected-error {{static assertion failed}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/237882 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
