[libc++] Fix lifetime issues of temporaries.
The ASAN build failed due to using pointers to a temporary whose
lifetime had expired.
Updating the libc++ Docker image to Ubuntu Focal caused some breakage.
This was temporary disabled in D112737. This re-enables two of these
tests.
Reviewed By: ldionne, #libc
Differential Revision: https://reviews.llvm.org/D113137
GitOrigin-RevId: 1e78d5d008f95b47834ce2438a9b0faf96c85985
diff --git a/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp b/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
index c92ed5b..2a4b3fa 100644
--- a/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
+++ b/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
@@ -10,9 +10,6 @@
// UNSUPPORTED: libcpp-has-no-localization
// UNSUPPORTED: libcpp-has-no-incomplete-format
-// TODO(mordante): Investigate these localization/format failures since updating the Docker image in CI
-// UNSUPPORTED: stdlib=libc++
-
// REQUIRES: locale.en_US.UTF-8
// REQUIRES: locale.fr_FR.UTF-8
@@ -50,9 +47,11 @@
!std::is_move_assignable_v<std::basic_format_context<OutIt, CharT>>);
std::basic_string<CharT> string = MAKE_STRING(CharT, "string");
- std::basic_format_args args =
- std::make_format_args<std::basic_format_context<OutIt, CharT>>(
- true, CharT('a'), 42, string);
+ // The type of the object is an exposition only type. The temporary is needed
+ // to extend the lifetype of the object since args stores a pointer to the
+ // data in this object.
+ auto format_arg_store = std::make_format_args<std::basic_format_context<OutIt, CharT>>(true, CharT('a'), 42, string);
+ std::basic_format_args args = format_arg_store;
{
std::basic_string<CharT> output;
diff --git a/test/std/utilities/format/format.formatter/format.context/format.context/locale.pass.cpp b/test/std/utilities/format/format.formatter/format.context/format.context/locale.pass.cpp
index 224c332..89f3a36 100644
--- a/test/std/utilities/format/format.formatter/format.context/format.context/locale.pass.cpp
+++ b/test/std/utilities/format/format.formatter/format.context/format.context/locale.pass.cpp
@@ -10,9 +10,6 @@
// UNSUPPORTED: libcpp-has-no-localization
// UNSUPPORTED: libcpp-has-no-incomplete-format
-// TODO(mordante): Investigate these localization/format failures since updating the Docker image in CI
-// UNSUPPORTED: stdlib=libc++
-
// REQUIRES: locale.en_US.UTF-8
// REQUIRES: locale.fr_FR.UTF-8
@@ -34,9 +31,11 @@
std::locale en_US{LOCALE_en_US_UTF_8};
std::locale fr_FR{LOCALE_fr_FR_UTF_8};
std::basic_string<CharT> string = MAKE_STRING(CharT, "string");
- std::basic_format_args args =
- std::make_format_args<std::basic_format_context<OutIt, CharT>>(
- true, CharT('a'), 42, string);
+ // The type of the object is an exposition only type. The temporary is needed
+ // to extend the lifetype of the object since args stores a pointer to the
+ // data in this object.
+ auto format_arg_store = std::make_format_args<std::basic_format_context<OutIt, CharT>>(true, CharT('a'), 42, string);
+ std::basic_format_args args = format_arg_store;
{
std::basic_string<CharT> output;