-// { dg-do compile { target c++23 } }
+// { dg-options "-lstdc++exp" }
+// { dg-do run { target c++23 } }
// { dg-require-effective-target stacktrace }
// { dg-add-options no_pch }
{
auto trace = std::stacktrace::current();
std::string s1 = std::to_string(trace.at(0));
- VERIFY( s1.contains("test_to_string():15") );
+ VERIFY( s1.contains("test_to_string()") );
+ VERIFY( s1.contains("output.cc:19") );
std::string s2 = std::to_string(trace);
VERIFY( s2.contains(s1) );
}
std::stacktrace_entry entry = trace.at(0);
std::string str = std::to_string(entry);
VERIFY( std::format("{}", entry) == str );
- VERIFY( std::format("{0:!<{1}}", entry, str.size() + 3) == (str + "!!!") );
+ auto len = str.size();
+ // with width
+ VERIFY( std::format("{0:{1}}", entry, len + 1) == (str + " ") );
+ // with align + width
+ VERIFY( std::format("{0:<{1}}", entry, len + 2) == (str + " ") );
+ VERIFY( std::format("{0:^{1}}", entry, len + 3) == (" " + str + " ") );
+ VERIFY( std::format("{0:>{1}}", entry, len + 4) == (" " + str) );
+ // with fill-and-align + width
+ VERIFY( std::format("{0:!<{1}}", entry, len + 2) == (str + "!!") );
+ VERIFY( std::format("{0:!^{1}}", entry, len + 3) == ("!" + str + "!!") );
+ VERIFY( std::format("{0:!>{1}}", entry, len + 4) == ("!!!!" + str) );
}
int main()
auto len = s1.size();
out.str("");
- auto s2 = std::format("{0:x^{1}}", j, len + 4);
- VERIFY( s2 == ("xx" + s1 + "xx") );
+ std::string s2;
+ // with width
+ s2 = std::format("{0:{1}}", j, len + 2);
+ VERIFY( s2 == (" " + s1) );
+ // with align + width
+ s2 = std::format("{0:>{1}}", j, len + 2);
+ VERIFY( s2 == (" " + s1) );
+ s2 = std::format("{0:<{1}}", j, len + 2);
+ VERIFY( s2 == (s1 + " ") );
+ // with fill-and-align + width
+ s2 = std::format("{0:x^{1}}", j, len + 5);
+ VERIFY( s2 == ("xx" + s1 + "xxx") );
#ifdef _GLIBCXX_USE_WCHAR_T
static_assert( std::is_default_constructible_v<std::formatter<std::thread::id, wchar_t>> );