mirror of https://github.com/catchorg/Catch2.git
Added type_to_string
This commit is contained in:
parent
0de60d8e7e
commit
e4d4fad597
|
@ -109,6 +109,7 @@
|
||||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
#include <catch2/internal/catch_test_spec_parser.hpp>
|
||||||
#include <catch2/internal/catch_textflow.hpp>
|
#include <catch2/internal/catch_textflow.hpp>
|
||||||
#include <catch2/internal/catch_to_string.hpp>
|
#include <catch2/internal/catch_to_string.hpp>
|
||||||
|
#include <catch2/internal/catch_type_to_string.hpp>
|
||||||
#include <catch2/internal/catch_uncaught_exceptions.hpp>
|
#include <catch2/internal/catch_uncaught_exceptions.hpp>
|
||||||
#include <catch2/internal/catch_unique_name.hpp>
|
#include <catch2/internal/catch_unique_name.hpp>
|
||||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__)
|
# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__)
|
||||||
|
|
||||||
|
# define CATCH_INTERNAL_TYPEID_DEMANGLE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__CUDACC__) && !defined(__clang__)
|
#if defined(__CUDACC__) && !defined(__clang__)
|
||||||
|
@ -73,6 +74,7 @@
|
||||||
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
|
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
|
||||||
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
|
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
|
||||||
|
|
||||||
|
# define CATCH_INTERNAL_TYPEID_DEMANGLE
|
||||||
#endif // __clang__ && !_MSC_VER
|
#endif // __clang__ && !_MSC_VER
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
|
||||||
|
// Copyright Catch2 Authors
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// SPDX-License-Identifier: BSL-1.0
|
||||||
|
#ifndef CATCH_TYPE_TO_STRING_HPP_INCLUDED
|
||||||
|
#define CATCH_TYPE_TO_STRING_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#if defined( CATCH_INTERNAL_TYPEID_DEMANGLE )
|
||||||
|
# include <memory>
|
||||||
|
# include <cxxabi.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
template <typename T> std::string type_to_string() {
|
||||||
|
#if defined( CATCH_INTERNAL_TYPEID_DEMANGLE )
|
||||||
|
const char* name = typeid( T ).name();
|
||||||
|
int status = 0;
|
||||||
|
std::unique_ptr<char, void ( * )( void* )> res{
|
||||||
|
abi::__cxa_demangle( name, NULL, NULL, &status ), std::free };
|
||||||
|
|
||||||
|
return status == 0 ? res.get() : name;
|
||||||
|
#else
|
||||||
|
return typeid( T ).name();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // CATCH_TYPE_TO_STRING_HPP_INCLUDED
|
Loading…
Reference in New Issue