llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: None (yronglin) <details> <summary>Changes</summary> Fix the location of `diag::note_constexpr_uninitialized_base`, make it same as current interpreter. --- Full diff: https://github.com/llvm/llvm-project/pull/100761.diff 3 Files Affected: - (modified) clang/lib/AST/Interp/EvaluationResult.cpp (+9-11) - (modified) clang/test/AST/Interp/constexpr-subobj-initialization.cpp (+7-11) - (modified) clang/test/SemaCXX/constexpr-subobj-initialization.cpp (+4-3) ``````````diff diff --git a/clang/lib/AST/Interp/EvaluationResult.cpp b/clang/lib/AST/Interp/EvaluationResult.cpp index 1b255711c7b36..57e12598d12e4 100644 --- a/clang/lib/AST/Interp/EvaluationResult.cpp +++ b/clang/lib/AST/Interp/EvaluationResult.cpp @@ -122,22 +122,20 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc, } // Check Fields in all bases - for (const Record::Base &B : R->bases()) { + unsigned BaseIndex = 0; + const CXXRecordDecl *CD = dyn_cast<CXXRecordDecl>(R->getDecl()); + for (const CXXBaseSpecifier &BS : CD->bases()) { + const Record::Base &B = *R->getBase(BaseIndex); Pointer P = BasePtr.atField(B.Offset); if (!P.isInitialized()) { - const Descriptor *Desc = BasePtr.getDeclDesc(); - if (Desc->asDecl()) - S.FFDiag(BasePtr.getDeclDesc()->asDecl()->getLocation(), - diag::note_constexpr_uninitialized_base) - << B.Desc->getType(); - else - S.FFDiag(BasePtr.getDeclDesc()->asExpr()->getExprLoc(), - diag::note_constexpr_uninitialized_base) - << B.Desc->getType(); - + SourceLocation TypeBeginLoc = BS.getBaseTypeLoc(); + SourceRange Range(TypeBeginLoc, BS.getEndLoc()); + S.FFDiag(TypeBeginLoc, diag::note_constexpr_uninitialized_base) + << B.Desc->getType() << Range; return false; } Result &= CheckFieldsInitialized(S, Loc, P, B.R); + BaseIndex++; } // TODO: Virtual bases diff --git a/clang/test/AST/Interp/constexpr-subobj-initialization.cpp b/clang/test/AST/Interp/constexpr-subobj-initialization.cpp index 4976b165468bd..4c067423aedfd 100644 --- a/clang/test/AST/Interp/constexpr-subobj-initialization.cpp +++ b/clang/test/AST/Interp/constexpr-subobj-initialization.cpp @@ -14,33 +14,29 @@ struct DelBase { constexpr DelBase() = delete; // expected-note {{'DelBase' has been explicitly marked deleted here}} }; -struct Foo : DelBase { +struct Foo : DelBase { // expected-note 2{{constructor of base class 'baseclass_uninit::DelBase' is not called}} constexpr Foo() {}; // expected-error {{call to deleted constructor of 'DelBase'}} }; -constexpr Foo f; // expected-error {{must be initialized by a constant expression}} \ - // expected-note {{constructor of base class 'baseclass_uninit::DelBase' is not called}} +constexpr Foo f; // expected-error {{must be initialized by a constant expression}} struct Bar : Foo { constexpr Bar() {}; }; -constexpr Bar bar; // expected-error {{must be initialized by a constant expression}} \ - // expected-note {{constructor of base class 'baseclass_uninit::DelBase' is not called}} +constexpr Bar bar; // expected-error {{must be initialized by a constant expression}} struct Base {}; -struct A : Base { +struct A : Base { // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}} constexpr A() : value() {} // expected-error {{member initializer 'value' does not name a non-static data member or base class}} }; -constexpr A a; // expected-error {{must be initialized by a constant expression}} \ - // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}} +constexpr A a; // expected-error {{must be initialized by a constant expression}} -struct B : Base { +struct B : Base { // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}} constexpr B() : {} // expected-error {{expected class member or base class name}} }; -constexpr B b; // expected-error {{must be initialized by a constant expression}} \ - // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}} +constexpr B b; // expected-error {{must be initialized by a constant expression}} } // namespace baseclass_uninit diff --git a/clang/test/SemaCXX/constexpr-subobj-initialization.cpp b/clang/test/SemaCXX/constexpr-subobj-initialization.cpp index cd096a9270937..f0252df1e2ce1 100644 --- a/clang/test/SemaCXX/constexpr-subobj-initialization.cpp +++ b/clang/test/SemaCXX/constexpr-subobj-initialization.cpp @@ -1,11 +1,12 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s namespace baseclass_uninit { struct DelBase { constexpr DelBase() = delete; // expected-note {{'DelBase' has been explicitly marked deleted here}} }; -struct Foo : DelBase { // expected-note 2{{constructor of base class 'DelBase' is not called}} +struct Foo : DelBase { // expected-note-re 2{{constructor of base class '{{.*}}DelBase' is not called}} constexpr Foo() {}; // expected-error {{call to deleted constructor of 'DelBase'}} }; constexpr Foo f; // expected-error {{must be initialized by a constant expression}} @@ -15,13 +16,13 @@ struct Bar : Foo { constexpr Bar bar; // expected-error {{must be initialized by a constant expression}} struct Base {}; -struct A : Base { // expected-note {{constructor of base class 'Base' is not called}} +struct A : Base { // expected-note-re {{constructor of base class '{{.*}}Base' is not called}} constexpr A() : value() {} // expected-error {{member initializer 'value' does not name a non-static data member or base class}} }; constexpr A a; // expected-error {{must be initialized by a constant expression}} -struct B : Base { // expected-note {{constructor of base class 'Base' is not called}} +struct B : Base { // expected-note-re {{constructor of base class '{{.*}}Base' is not called}} constexpr B() : {} // expected-error {{expected class member or base class name}} }; `````````` </details> https://github.com/llvm/llvm-project/pull/100761 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits