From: Timm Bäder Date: Sat, 11 Mar 2023 08:55:22 +0000 (+0100) Subject: [clang][Interp] Fix diagnostics for calling non-constexpr constructors X-Git-Tag: upstream/17.0.6~12866 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58cf70b2cdc17a905f7db2ec5a6f9d497f9bd133;p=platform%2Fupstream%2Fllvm.git [clang][Interp] Fix diagnostics for calling non-constexpr constructors Differential Revision: https://reviews.llvm.org/D145841 --- diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 665f60d..e5c9b26 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1350,7 +1350,7 @@ bool ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) { if (const auto CtorExpr = dyn_cast(Initializer)) { const Function *Func = getFunction(CtorExpr->getConstructor()); - if (!Func || !Func->isConstexpr()) + if (!Func) return false; // The This pointer is already on the stack because this is an initializer, diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp index cfa9729..6cb106a 100644 --- a/clang/test/AST/Interp/cxx20.cpp +++ b/clang/test/AST/Interp/cxx20.cpp @@ -207,13 +207,15 @@ namespace ConstThis { // ref-note {{declared const here}} int a; public: - constexpr Foo() { + constexpr Foo() { // expected-note {{declared here}} this->a = 10; T = 13; // expected-error {{cannot assign to non-static data member 'T' with const-qualified type}} \ // ref-error {{cannot assign to non-static data member 'T' with const-qualified type}} } }; constexpr Foo F; // expected-error {{must be initialized by a constant expression}} \ + // FIXME: The following note is wrong. \ + // expected-note {{undefined constructor 'Foo' cannot be used in a constant expression}} \ // ref-error {{must be initialized by a constant expression}} diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp index 37cdf34..a7085e4 100644 --- a/clang/test/AST/Interp/records.cpp +++ b/clang/test/AST/Interp/records.cpp @@ -308,7 +308,7 @@ namespace MI { }; namespace DeriveFailures { - struct Base { // ref-note 2{{declared here}} + struct Base { // ref-note 2{{declared here}} expected-note {{declared here}} int Val; }; @@ -316,13 +316,15 @@ namespace DeriveFailures { int OtherVal; constexpr Derived(int i) : OtherVal(i) {} // ref-error {{never produces a constant expression}} \ - // ref-note 2{{non-constexpr constructor 'Base' cannot be used in a constant expression}} + // ref-note 2{{non-constexpr constructor 'Base' cannot be used in a constant expression}} \ + // expected-note {{non-constexpr constructor 'Base' cannot be used in a constant expression}} }; constexpr Derived D(12); // ref-error {{must be initialized by a constant expression}} \ // ref-note {{in call to 'Derived(12)'}} \ // ref-note {{declared here}} \ - // expected-error {{must be initialized by a constant expression}} + // expected-error {{must be initialized by a constant expression}} \ + // expected-note {{in call to 'Derived(12)'}} static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \ // ref-note {{initializer of 'D' is not a constant expression}} \ // expected-error {{not an integral constant expression}} \ @@ -348,7 +350,8 @@ namespace DeriveFailures { }; struct YetAnotherDerived : YetAnotherBase { - using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}} + using YetAnotherBase::YetAnotherBase; // ref-note {{declared here}} \ + // expected-note {{declared here}} int OtherVal; constexpr bool doit() const { return Val == OtherVal; } @@ -356,8 +359,8 @@ namespace DeriveFailures { constexpr YetAnotherDerived Oops(0); // ref-error {{must be initialized by a constant expression}} \ // ref-note {{constructor inherited from base class 'YetAnotherBase' cannot be used in a constant expression}} \ - // expected-error {{must be initialized by a constant expression}} - // FIXME: Missing reason for rejection. + // expected-error {{must be initialized by a constant expression}} \ + // expected-note {{constructor inherited from base class 'YetAnotherBase' cannot be used in a constant expression}} }; namespace EmptyCtor {