[PATCH] D153375: [Clang] Fix incorrect use of direct initialization with copy initialization

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 30 15:08:59 PDT 2023


shafik updated this revision to Diff 536451.
shafik marked an inline comment as done.
shafik added a comment.

- Added release note
- Added test case


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

https://reviews.llvm.org/D153375

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp


Index: clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
===================================================================
--- clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
+++ clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp
@@ -283,3 +283,13 @@
   F f4(const bool x) { return F{x}; }
 #endif
 }
+
+namespace GH62503 {
+enum class E {E1};
+
+void f() {
+  E e;
+  e = {E::E1};
+  e = {0}; // expected-error {{cannot initialize a value of type 'E' with an rvalue of type 'int'}}
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15441,8 +15441,8 @@
     // C++11 5.17p9:
     //   The meaning of x = {v} [...] is that of x = T(v) [...]. The meaning
     //   of x = {} is x = T().
-    InitializationKind Kind = InitializationKind::CreateDirectList(
-        RHSExpr->getBeginLoc(), RHSExpr->getBeginLoc(), RHSExpr->getEndLoc());
+    InitializationKind Kind =
+        InitializationKind::CreateCopy(RHSExpr->getBeginLoc(), OpLoc);
     InitializedEntity Entity =
         InitializedEntity::InitializeTemporary(LHSExpr->getType());
     InitializationSequence InitSeq(*this, Entity, Kind, RHSExpr);
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -561,6 +561,9 @@
   when an immediate invocation appears as a part of an expression that produces
   temporaries.
   (`#60709 <https://github.com/llvm/llvm-project/issues/60709>`_).
+- Fix use of direct-intialization over copy-initialization when using
+  = form of brace-or-equal-initialzer. This fixes
+  (`#63503 <https://github.com/llvm/llvm-project/issues/62503>`_).
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153375.536451.patch
Type: text/x-patch
Size: 1855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230630/191906f0/attachment.bin>


More information about the cfe-commits mailing list