llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> We can't call `getNumElems()` for unknown-size arrays. --- Full diff: https://github.com/llvm/llvm-project/pull/213639.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Context.cpp (+2-1) - (modified) clang/test/AST/ByteCode/cxx26.cpp (+12) ``````````diff diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index b913d2a9f539c..9f1d9b899052d 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -208,7 +208,8 @@ bool Context::evaluateStringRepr(State &Parent, const Expr *SizeExpr, return false; } - if (!Ptr.isLive() || !Ptr.getFieldDesc()->isPrimitiveArray()) + if (!Ptr.isLive() || !Ptr.isInitialized() || Ptr.isUnknownSizeArray() || + !Ptr.getFieldDesc()->isPrimitiveArray()) return false; // Must be char. diff --git a/clang/test/AST/ByteCode/cxx26.cpp b/clang/test/AST/ByteCode/cxx26.cpp index 769deb28cdf50..9dc6270b9d551 100644 --- a/clang/test/AST/ByteCode/cxx26.cpp +++ b/clang/test/AST/ByteCode/cxx26.cpp @@ -91,3 +91,15 @@ namespace ConstexprUnknownReference { } } + +namespace UnknownSizeArrayString { + constexpr const char foo[] = {bar}; // both-error {{use of undeclared identifier}} \ + // ref-note {{declared here}} + struct S { + constexpr int size() const { return 4; } + constexpr const char *data() const { return foo; } + }; + static_assert(false, S{}); // both-error {{the message in a static assertion must be produced by a constant expression}} \ + // ref-note {{initializer of 'foo' is unknown}} \ + // both-error {{static assertion failed}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/213639 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
