[clang] Refine handling of C++20 aggregate initialization by offsetof · Pull Request #131320 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-clang

Author: None (offsetof)

Changes

Fixes #88089


Full diff: https://github.com/llvm/llvm-project/pull/131320.diff

2 Files Affected:

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 56ec33fe37bf3..11db8608960ce 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6714,7 +6714,8 @@ void InitializationSequence::InitializeFrom(Sema &S, OverloadCandidateSet::iterator Best; OverloadingResult OR = getFailedCandidateSet().BestViableFunction( S, Kind.getLocation(), Best); - if (OR != OverloadingResult::OR_Deleted) { + if (OR != OverloadingResult::OR_Deleted && + Kind.getKind() == InitializationKind::IK_Direct) { // C++20 [dcl.init] 17.6.2.2: // - Otherwise, if no constructor is viable, the destination type is // an diff --git a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.general/p16-cxx20.cpp b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.general/p16-cxx20.cpp index 1ad205d769c38..1ef74bb66b4de 100644 --- a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.general/p16-cxx20.cpp +++ b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.general/p16-cxx20.cpp @@ -1,18 +1,34 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s -// If the initializer is (), the object is value-initialized.

-// expected-no-diagnostics namespace GH69890 { -struct A {

-};

+} // namespace GH69890 + +namespace P0960R3 {

-struct B : A {

-};

-static_assert(B().x == 0); -static_assert(B().y == 0); -}

+} // namespace P0960R3