[PATCH] D136920: [clang][Interp] Array initialization via CXXConstructExpr
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 22 09:53:51 PST 2022
aaron.ballman added inline comments.
================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:962-963
+ } else if (const auto *Ctor = dyn_cast<CXXConstructExpr>(Initializer)) {
+ const ArrayType *AT = Ctor->getType()->getAsArrayTypeUnsafe();
+ const auto *CAT = cast<ConstantArrayType>(AT);
+ size_t NumElems = CAT->getSize().getZExtValue();
----------------
This should go through `ASTContext::getConstantArrayType()`. It may also be worth a comment mentioning that VLAs can't have initializers and an unbounded array has known bounds if it has an initializer, as I suspect that's the reason you're not handling either of those here?
================
Comment at: clang/test/AST/Interp/arrays.cpp:188-200
+class A {
+public:
+ int a;
+ constexpr A(int m = 2) : a(10 + m) {}
+};
+class B {
+public:
----------------
I'd like to see a test for when the class ends with a flexible array member (ctor shouldn't be called for that case because we don't know how many trailing objects there will be). That could show up as an unbounded member.
Also, a test case where the ctor will execute UB, to demonstrate we properly diagnose arrays of default-constructed objects.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136920/new/
https://reviews.llvm.org/D136920
More information about the cfe-commits
mailing list