Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWG-3515: [stacktrace.basic.nonmem]: operator<< should be less templatized #3236

Merged
merged 2 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
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