This revision was automatically updated to reflect the committed changes.
Closed by commit rGc77a91bb7ba7: [clang] Remove overly restrictive aggregate 
paren init logic (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140327/new/

https://reviews.llvm.org/D140327

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===================================================================
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -1,9 +1,25 @@
 // RUN: %clang_cc1 -std=c++20 %s -emit-llvm -triple x86_64-unknown-linux-gnu 
-o - | FileCheck %s
 
+template <typename T>
+struct IsChar {
+  constexpr operator bool() const { return false; }
+};
+
+template<>
+struct IsChar<char> {
+  constexpr operator bool() const { return true; }
+};
+
+template <typename T>
+concept SameAsChar = (bool)IsInt<T>();
+
 // CHECK-DAG: [[STRUCT_A:%.*]] = type { i8, double }
 struct A {
   char i;
   double j;
+
+  template <SameAsChar T>
+  operator T() const { return i; };
 };
 
 // CHECK-DAG: [[STRUCT_B:%.*]] = type { [[STRUCT_A]], i32 }
@@ -29,6 +45,7 @@
 struct E {
   int a;
   const char* fn = __builtin_FUNCTION();
+  ~E() {};
 };
 
 // CHECK-DAG: [[STRUCT_F:%.*]] = type { i8 }
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5930,25 +5930,6 @@
   return false;
 }
 
-static bool onlyHasDefaultedCtors(OverloadCandidateSet &OCS) {
-  if (OCS.size() != 3)
-    return false;
-
-  bool HasDefaultCtor = false, HasCopyCtor = false, HasMoveCtor = false;
-  for (const auto &Candidate : OCS) {
-    if (auto *Ctor = dyn_cast_or_null<CXXConstructorDecl>(Candidate.Function);
-        Ctor != nullptr && Ctor->isDefaulted()) {
-      if (Ctor->isDefaultConstructor())
-        HasDefaultCtor = true;
-      else if (Ctor->isCopyConstructor())
-        HasCopyCtor = true;
-      else if (Ctor->isMoveConstructor())
-        HasMoveCtor = true;
-    }
-  }
-  return HasDefaultCtor && HasCopyCtor && HasMoveCtor;
-}
-
 void InitializationSequence::InitializeFrom(Sema &S,
                                             const InitializedEntity &Entity,
                                             const InitializationKind &Kind,
@@ -6196,8 +6177,7 @@
       if (const auto *RD =
               
dyn_cast<CXXRecordDecl>(DestType->getAs<RecordType>()->getDecl());
           S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
-          getFailureKind() == FK_ConstructorOverloadFailed &&
-          onlyHasDefaultedCtors(getFailedCandidateSet())) {
+          getFailureKind() == FK_ConstructorOverloadFailed) {
         // C++20 [dcl.init] 17.6.2.2:
         //   - Otherwise, if no constructor is viable, the destination type is
         //   an


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===================================================================
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -1,9 +1,25 @@
 // RUN: %clang_cc1 -std=c++20 %s -emit-llvm -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
 
+template <typename T>
+struct IsChar {
+  constexpr operator bool() const { return false; }
+};
+
+template<>
+struct IsChar<char> {
+  constexpr operator bool() const { return true; }
+};
+
+template <typename T>
+concept SameAsChar = (bool)IsInt<T>();
+
 // CHECK-DAG: [[STRUCT_A:%.*]] = type { i8, double }
 struct A {
   char i;
   double j;
+
+  template <SameAsChar T>
+  operator T() const { return i; };
 };
 
 // CHECK-DAG: [[STRUCT_B:%.*]] = type { [[STRUCT_A]], i32 }
@@ -29,6 +45,7 @@
 struct E {
   int a;
   const char* fn = __builtin_FUNCTION();
+  ~E() {};
 };
 
 // CHECK-DAG: [[STRUCT_F:%.*]] = type { i8 }
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5930,25 +5930,6 @@
   return false;
 }
 
-static bool onlyHasDefaultedCtors(OverloadCandidateSet &OCS) {
-  if (OCS.size() != 3)
-    return false;
-
-  bool HasDefaultCtor = false, HasCopyCtor = false, HasMoveCtor = false;
-  for (const auto &Candidate : OCS) {
-    if (auto *Ctor = dyn_cast_or_null<CXXConstructorDecl>(Candidate.Function);
-        Ctor != nullptr && Ctor->isDefaulted()) {
-      if (Ctor->isDefaultConstructor())
-        HasDefaultCtor = true;
-      else if (Ctor->isCopyConstructor())
-        HasCopyCtor = true;
-      else if (Ctor->isMoveConstructor())
-        HasMoveCtor = true;
-    }
-  }
-  return HasDefaultCtor && HasCopyCtor && HasMoveCtor;
-}
-
 void InitializationSequence::InitializeFrom(Sema &S,
                                             const InitializedEntity &Entity,
                                             const InitializationKind &Kind,
@@ -6196,8 +6177,7 @@
       if (const auto *RD =
               dyn_cast<CXXRecordDecl>(DestType->getAs<RecordType>()->getDecl());
           S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
-          getFailureKind() == FK_ConstructorOverloadFailed &&
-          onlyHasDefaultedCtors(getFailedCandidateSet())) {
+          getFailureKind() == FK_ConstructorOverloadFailed) {
         // C++20 [dcl.init] 17.6.2.2:
         //   - Otherwise, if no constructor is viable, the destination type is
         //   an
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to