aboutsummaryrefslogtreecommitdiff
path: root/clang/docs
diff options
context:
space:
mode:
authorGábor Spaits <gaborspaits1@gmail.com>2024-06-18 20:45:23 +0200
committerGitHub <noreply@github.com>2024-06-18 20:45:23 +0200
commitf80bd9b8a8103f39f5fece019abf86d41098cec1 (patch)
tree1a3f9cdd0180546f2980edb732836d436666025b /clang/docs
parent04a75f54a11f1f2640a211a81120966c7a24d05b (diff)
downloadllvm-f80bd9b8a8103f39f5fece019abf86d41098cec1.zip
llvm-f80bd9b8a8103f39f5fece019abf86d41098cec1.tar.gz
llvm-f80bd9b8a8103f39f5fece019abf86d41098cec1.tar.bz2
[Sema][CTAD] Allow user defined conversion for copy-list-initialization (#94752)
Fixes #62925. The following code: ```cpp #include <map> int main() { std::map m1 = {std::pair{"foo", 2}, {"bar", 3}}; // guide #2 std::map m2(m1.begin(), m1.end()); // guide #1 } ``` Is rejected by clang, but accepted by both gcc and msvc: https://godbolt.org/z/6v4fvabb5 . So basically CTAD with copy-list-initialization is rejected. Note that this exact code is also used in a cppreference article: https://en.cppreference.com/w/cpp/container/map/deduction_guides I checked the C++11 and C++20 standard drafts to see whether suppressing user conversion is the correct thing to do for user conversions. Based on the standard I don't think that it is correct. ``` 13.3.1.4 Copy-initialization of class by user-defined conversion [over.match.copy] Under the conditions specified in 8.5, as part of a copy-initialization of an object of class type, a user-defined conversion can be invoked to convert an initializer expression to the type of the object being initialized. Overload resolution is used to select the user-defined conversion to be invoked ``` So we could use user defined conversions according to the standard. ``` If a narrowing conversion is required to initialize any of the elements, the program is ill-formed. ``` We should not do narrowing. ``` In copy-list-initialization, if an explicit constructor is chosen, the initialization is ill-formed. ``` We should not use explicit constructors.
Diffstat (limited to 'clang/docs')
-rw-r--r--clang/docs/ReleaseNotes.rst6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bbbc043..0f958d2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -207,6 +207,12 @@ C++20 Feature Support
to update the ``__cpp_concepts`` macro to `202002L`. This enables
``<expected>`` from libstdc++ to work correctly with Clang.
+- User defined constructors are allowed for copy-list-initialization with CTAD.
+ The example code for deduction guides for std::map in
+ (`cppreference <https://en.cppreference.com/w/cpp/container/map/deduction_guides>`_)
+ will now work.
+ (#GH62925).
+
C++23 Feature Support
^^^^^^^^^^^^^^^^^^^^^