[PATCH] D128248: [clang] Avoid an assertion in APValue::hasArrayFiller()

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 21 02:50:38 PDT 2022


tbaeder updated this revision to Diff 438612.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128248/new/

https://reviews.llvm.org/D128248

Files:
  clang/include/clang/AST/APValue.h
  clang/test/SemaCXX/constexpr-array-init.cpp


Index: clang/test/SemaCXX/constexpr-array-init.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/constexpr-array-init.cpp
@@ -0,0 +1,19 @@
+
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+struct Foo {
+  int a; // expected-note {{subobject declared here}}
+  constexpr Foo()
+      : a(get_int()) {
+  }
+
+  constexpr int get_int() {
+    return 5;
+  }
+};
+
+
+static constexpr Foo bar[2][1] = { // expected-error {{constexpr variable 'bar' must be initialized by a constant expression}} \
+                                   // expected-note {{subobject of type 'int' is not initialized}}
+    {{}},
+};
Index: clang/include/clang/AST/APValue.h
===================================================================
--- clang/include/clang/AST/APValue.h
+++ clang/include/clang/AST/APValue.h
@@ -508,6 +508,8 @@
     return const_cast<APValue*>(this)->getArrayInitializedElt(I);
   }
   bool hasArrayFiller() const {
+    if (!isArray())
+      return false;
     return getArrayInitializedElts() != getArraySize();
   }
   APValue &getArrayFiller() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128248.438612.patch
Type: text/x-patch
Size: 1110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220621/c1e9c1b0/attachment-0001.bin>


More information about the cfe-commits mailing list