Fznamznon updated this revision to Diff 503020. Fznamznon added a comment. Rebase and update test comment.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D145486/new/ https://reviews.llvm.org/D145486 Files: clang/lib/AST/ExprConstant.cpp clang/test/SemaCXX/constexpr-single-element-array.cpp Index: clang/test/SemaCXX/constexpr-single-element-array.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/constexpr-single-element-array.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=c++20 -verify %s + +// This test makes sure that a single element array doesn't produce +// spurious errors during constexpr evaluation. + +// expected-no-diagnostics +struct Sub { int x; }; + +struct S { + constexpr S() { Arr[0] = Sub{}; } + Sub Arr[1]; +}; + +constexpr bool test() { + S s; + return true; +} + +static_assert(test()); Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -10917,7 +10917,7 @@ for (unsigned I = OldElts; I < N; ++I) Value->getArrayInitializedElt(I) = Filler; - if (HasTrivialConstructor && N == FinalSize) { + if (HasTrivialConstructor && N == FinalSize && FinalSize != 1) { // If we have a trivial constructor, only evaluate it once and copy // the result into all the array elements. APValue &FirstResult = Value->getArrayInitializedElt(0);
Index: clang/test/SemaCXX/constexpr-single-element-array.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/constexpr-single-element-array.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=c++20 -verify %s + +// This test makes sure that a single element array doesn't produce +// spurious errors during constexpr evaluation. + +// expected-no-diagnostics +struct Sub { int x; }; + +struct S { + constexpr S() { Arr[0] = Sub{}; } + Sub Arr[1]; +}; + +constexpr bool test() { + S s; + return true; +} + +static_assert(test()); Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -10917,7 +10917,7 @@ for (unsigned I = OldElts; I < N; ++I) Value->getArrayInitializedElt(I) = Filler; - if (HasTrivialConstructor && N == FinalSize) { + if (HasTrivialConstructor && N == FinalSize && FinalSize != 1) { // If we have a trivial constructor, only evaluate it once and copy // the result into all the array elements. APValue &FirstResult = Value->getArrayInitializedElt(0);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits