Skip to content

Commit

Permalink
LWG-3515: [stacktrace.basic.nonmem]: operator<< should be less temp…
Browse files Browse the repository at this point in the history
…latized (#3236)
  • Loading branch information
JMazurkiewicz authored Nov 19, 2022
1 parent 299abb0 commit 10e1366
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stl/inc/stacktrace
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ _NODISCARD string to_string(const basic_stacktrace<_Alloc>& _St) {
return _Result;
}

_EXPORT_STD template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const stacktrace_entry& _Fx) {
_EXPORT_STD template <int = 0>
ostream& operator<<(ostream& _Os, const stacktrace_entry& _Fx) {
return _Os << _STD to_string(_Fx);
}

_EXPORT_STD template <class _CharT, class _Traits, class _Alloc>
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const basic_stacktrace<_Alloc>& _St) {
_EXPORT_STD template <class _Alloc>
ostream& operator<<(ostream& _Os, const basic_stacktrace<_Alloc>& _St) {
return _Os << _STD to_string(_St);
}

Expand Down
31 changes: 31 additions & 0 deletions tests/std/tests/P0881R7_stacktrace/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <concepts>
#include <cstddef>
#include <filesystem>
#include <iterator>
#include <memory_resource>
#include <ostream>
#include <sstream>
#include <stacktrace>
#include <stdexcept>
Expand All @@ -20,6 +23,34 @@

using namespace std;

#if defined(__cpp_lib_concepts) // TRANSITION, GH-395
template <class Ostream, class Alloc = allocator<stacktrace_entry>>
concept CanPrintStacktrace =
requires(Ostream& os, const stacktrace_entry& f, const basic_stacktrace<Alloc>& st) {
{ os << f } -> same_as<basic_ostream<typename Ostream::char_type, typename Ostream::traits_type>&>;
{ os << st } -> same_as<basic_ostream<typename Ostream::char_type, typename Ostream::traits_type>&>;
};

template <class CharT>
struct FancyCharTraits : char_traits<CharT> {};

static_assert(CanPrintStacktrace<ostream>);
static_assert(CanPrintStacktrace<ostringstream>);
static_assert(CanPrintStacktrace<ostream, pmr::polymorphic_allocator<stacktrace_entry>>);

static_assert(!CanPrintStacktrace<wostream>);
static_assert(!CanPrintStacktrace<wostringstream>);
static_assert(!CanPrintStacktrace<wostream, pmr::polymorphic_allocator<stacktrace_entry>>);

using FancyCharStream = basic_ostream<char, FancyCharTraits<char>>;
static_assert(!CanPrintStacktrace<FancyCharStream>);
static_assert(!CanPrintStacktrace<FancyCharStream, pmr::polymorphic_allocator<stacktrace_entry>>);

using FancyWcharStream = basic_ostream<wchar_t, FancyCharTraits<wchar_t>>;
static_assert(!CanPrintStacktrace<FancyWcharStream>);
static_assert(!CanPrintStacktrace<FancyWcharStream, pmr::polymorphic_allocator<stacktrace_entry>>);
#endif // defined(__cpp_lib_concepts)

[[maybe_unused]] const int base_line = __LINE__;

// Note: the below assumes that tail call optimization is disabled, which is the case in /Od
Expand Down

0 comments on commit 10e1366

Please sign in to comment.