[PATCH] D135025: [clang][Interp] Support base class constructors
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 14 00:33:02 PDT 2022
tbaeder marked an inline comment as done.
tbaeder added inline comments.
================
Comment at: clang/test/AST/Interp/records.cpp:209
+ static_assert(d.getA() == 20);
+ static_assert(d.getB() == 30);
+};
----------------
aaron.ballman wrote:
> I'd appreciate some more failure test cases, if they're not already covered elsewhere:
> ```
> struct Base {
> int Val;
> };
>
> struct Derived : Base {
> int OtherVal;
>
> constexpr Derived(int i) : OtherVal(i) {}
> };
>
> // Something here should be diagnosed; either because the Derived ctor is not a
> // valid constexpr function or because we're accessing an uninitialized member.
> constexpr Derived D(12);
> static_assert(D.Val == 0);
>
>
> // Another test is when a constexpr ctor calls a non-constexpr base class ctor.
> struct AnotherBase {
> int Val;
> constexpr AnotherBase(int i) : Val(12 / i) {}
> };
>
> struct AnotherDerived : AnotherBase {
> constexpr AnotherDerived(int i) : AnotherBase(i) {}
> };
> constexpr AnotherDerived Derp(0);
>
> // Skipping the derived class constructor is also
> // interesting to consider:
> struct YetAnotherBase {
> int Val;
> constexpr YetAnotherBase(int i) : Val(i) {}
> };
>
> struct YetAnotherDerived : YetAnotherBase {
> using YetAnotherBase::YetAnotherBase;
>
> int OtherVal;
>
> constexpr bool doit() const { return Val == OtherVal; }
> };
>
> constexpr YetAnotherDerived Oops(0);
> ```
Thanks for the tests. I added them but it doesn't look very good.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135025/new/
https://reviews.llvm.org/D135025
More information about the cfe-commits
mailing list