[PATCH] D41977: [libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.
Eric Fiselier via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 11 19:33:06 PST 2018
EricWF created this revision.
EricWF added reviewers: rsmith, mclow.lists.
See https://bugs.llvm.org/show_bug.cgi?id=20855
Libc++ goes out of it's way to diagnose `std::tuple` constructions which are UB due to lifetime bugs caused by reference creation. For example:
// The 'const std::string&' is created *inside* the tuple constructor, and its lifetime is over before the end of the constructor call.
std::tuple<int, const std::string&> t(std::make_tuple(42, "abc"));
However, we are over-aggressive and we incorrectly diagnose cases such as:
void foo(std::tuple<int const&, int const&> const&);
foo(std::make_tuple(42, 42));
This patch fixes the incorrectly diagnosed cases, as well as converting the diagnostic to use the newly added Clang trait `__reference_binds_to_temporary`. The new trait allows us to diagnose cases we previously couldn't such as:
std::tuple<int, const std::string&> t(42, "abc");
https://reviews.llvm.org/D41977
Files:
include/tuple
test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41977.129573.patch
Type: text/x-patch
Size: 6009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180112/8395cc22/attachment.bin>
More information about the cfe-commits
mailing list