Skip to content

Commit

Permalink
[libc++] Rewrite the tuple constructors to be strictly Standards conf…
Browse files Browse the repository at this point in the history
…orming

This nasty patch rewrites the tuple constructors to match those defined
by the Standard. We were previously providing several extensions in those
constructors - those extensions are removed by this patch.

The issue with those extensions is that we've had numerous bugs filed
against us over the years for problems essentially caused by them. As a
result, people are unable to use tuple in ways that are blessed by the
Standard, all that for the perceived benefit of providing them extensions
that they never asked for.

Since this is an API break, I communicated it in the release notes.
I do not foresee major issues with this break because I don't think the
extensions are too widely relied upon, but we can ship it and see if we
get complaints before the next LLVM release - that will give us some
amount of information regarding how much use these extensions have.

Differential Revision: https://reviews.llvm.org/D96523
  • Loading branch information
ldionne committed Apr 23, 2021
1 parent 7deb970 commit a3ab512
Show file tree
Hide file tree
Showing 25 changed files with 567 additions and 835 deletions.
13 changes: 12 additions & 1 deletion libcxx/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,15 @@ New Features
API Changes
-----------

- ...
- There has been several changes in the tuple constructors provided by libc++.
Those changes were made as part of an effort to regularize libc++'s tuple
implementation, which contained several subtle bugs due to these extensions.
If you notice a build breakage when initializing a tuple, make sure you
properly initialize all the tuple elements - this is probably the culprit.

In particular, the extension allowing tuples to be constructed from fewer
elements than the number of elements in the tuple (in which case the remaining
elements would be default-constructed) has been removed. See https://godbolt.org/z/sqozjd.

Also, the extension allowing a tuple to be constructed from an array has been
removed. See https://godbolt.org/z/5esqbW.
27 changes: 0 additions & 27 deletions libcxx/docs/UsingLibcxx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,6 @@ thread safety annotations.
headers. The intended use case is for clients who wish to use the libc++
headers without taking a dependency on the libc++ library itself.

**_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION**:
This macro is used to re-enable an extension in `std::tuple` which allowed
it to be implicitly constructed from fewer initializers than contained
elements. Elements without an initializer are default constructed. For example:

.. code-block:: cpp
std::tuple<std::string, int, std::error_code> foo() {
return {"hello world", 42}; // default constructs error_code
}
Since libc++ 4.0 this extension has been disabled by default. This macro
may be defined to re-enable it in order to support existing code that depends
on the extension. New use of this extension should be discouraged.
See `PR 27374 <https://llvm.org/PR27374>`_ for more information.

Note: The "reduced-arity-initialization" extension is still offered but only
for explicit conversions. Example:

.. code-block:: cpp
auto foo() {
using Tup = std::tuple<std::string, int, std::error_code>;
return Tup{"hello world", 42}; // explicit constructor called. OK.
}
**_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS**:
This macro disables the additional diagnostics generated by libc++ using the
`diagnose_if` attribute. These additional diagnostics include checks for:
Expand Down
Loading

0 comments on commit a3ab512

Please sign in to comment.