Skip to content

Commit f14f07c

Browse files
committed
Remove STL source location
1 parent 2f38e89 commit f14f07c

File tree

5 files changed

+33
-44
lines changed

5 files changed

+33
-44
lines changed

projects/core/include/tempest/assert.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace tempest::assertion::detail
1919
} // namespace tempest::assertion::detail
2020

2121
#define TEMPEST_ASSERT(expr) \
22-
tempest::assertion::detail::do_basic_assrtt((expr), tempest::source_location::current(), #expr)
22+
tempest::assertion::detail::do_basic_assrtt((expr), TEMPEST_CURRENT_SOURCE_LOCATION(), #expr)
2323

2424
#else
2525

projects/core/include/tempest/memory.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ namespace tempest
200200
{
201201
public:
202202
virtual ~abstract_allocator() = default;
203-
virtual void* allocate(size_t size, size_t alignment, source_location loc = source_location::current()) = 0;
203+
virtual void* allocate(size_t size, size_t alignment, source_location loc = TEMPEST_CURRENT_SOURCE_LOCATION()) = 0;
204204
virtual void deallocate(void* ptr) = 0;
205205
};
206206

@@ -217,7 +217,7 @@ namespace tempest
217217
stack_allocator& operator=(stack_allocator&& rhs) noexcept;
218218

219219
[[nodiscard]] void* allocate(size_t size, size_t alignment,
220-
source_location loc = source_location::current()) override;
220+
source_location loc = TEMPEST_CURRENT_SOURCE_LOCATION()) override;
221221
void deallocate(void* ptr) override;
222222

223223
size_t get_marker() const noexcept;
@@ -243,7 +243,7 @@ namespace tempest
243243
heap_allocator& operator=(heap_allocator&& rhs) noexcept;
244244

245245
[[nodiscard]] void* allocate(size_t size, size_t alignment,
246-
source_location loc = source_location::current()) override;
246+
source_location loc = TEMPEST_CURRENT_SOURCE_LOCATION()) override;
247247
void deallocate(void* ptr) override;
248248

249249
private:

projects/core/include/tempest/meta.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace tempest::core
1313
template <typename T>
1414
constexpr auto get_type_name() noexcept
1515
{
16-
auto src = tempest::source_location::current();
16+
auto src = TEMPEST_CURRENT_SOURCE_LOCATION();
1717
string_view here = src.function_name();
1818

1919
#if defined(_MSC_VER) && !defined(__clang__)

projects/core/include/tempest/source_location.hpp

+26-37
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,13 @@
33

44
#include <tempest/int.hpp>
55

6-
#include <source_location>
7-
86
namespace tempest
97
{
108
struct source_location
119
{
1210
public:
13-
#if defined(_MSC_VER)
14-
static consteval source_location current(const uint32_t line = __builtin_LINE(),
15-
const uint32_t column = __builtin_COLUMN(),
16-
const char* file = __builtin_FILE(),
17-
const char* func = __builtin_FUNCSIG()) noexcept;
18-
#elif defined(__GNUC__)
19-
static consteval source_location current(const uint32_t line = __builtin_LINE(),
20-
const uint32_t column = __builtin_COLUMN(),
21-
const char* file = __builtin_FILE(),
22-
const char* func = __builtin_source_location()->_M_function_name) noexcept;
23-
#else
24-
#error "Unsupported compiler."
25-
#endif
26-
2711
constexpr source_location() noexcept = default;
12+
consteval source_location(const uint32_t line, const uint32_t column, const char* file, const char* func);
2813

2914
constexpr const char* file_name() const noexcept;
3015
constexpr const char* function_name() const noexcept;
@@ -33,47 +18,51 @@ namespace tempest
3318
constexpr size_t column() const noexcept;
3419

3520
private:
36-
struct impl
37-
{
38-
const char* _file = nullptr;
39-
const char* _function = nullptr;
40-
uint32_t _line = 0;
41-
uint32_t _column = 0;
42-
};
43-
44-
impl _impl;
21+
const char* _file = nullptr;
22+
const char* _function = nullptr;
23+
uint32_t _line = 0;
24+
uint32_t _column = 0;
4525
};
4626

47-
inline consteval source_location source_location::current(const uint32_t line, const uint32_t column,
48-
const char* file, const char* func) noexcept
27+
inline consteval source_location::source_location(const uint32_t line, const uint32_t column, const char* file,
28+
const char* func)
29+
: _file{file}, _function{func}, _line{line}, _column{column}
4930
{
50-
source_location loc;
51-
loc._impl._file = file;
52-
loc._impl._function = func;
53-
loc._impl._line = line;
54-
loc._impl._column = column;
55-
return loc;
5631
}
5732

5833
inline constexpr const char* source_location::file_name() const noexcept
5934
{
60-
return _impl._file;
35+
return _file;
6136
}
6237

6338
inline constexpr const char* source_location::function_name() const noexcept
6439
{
65-
return _impl._function;
40+
return _function;
6641
}
6742

6843
inline constexpr size_t source_location::line() const noexcept
6944
{
70-
return _impl._line;
45+
return _line;
7146
}
7247

7348
inline constexpr size_t source_location::column() const noexcept
7449
{
75-
return _impl._column;
50+
return _column;
7651
}
7752
} // namespace tempest
7853

54+
#if defined(_MSC_VER)
55+
56+
#define TEMPEST_CURRENT_SOURCE_LOCATION() \
57+
::tempest::source_location::source_location(__builtin_LINE(), __builtin_COLUMN(), __builtin_FILE(), \
58+
__builtin_FUNCSIG())
59+
60+
#elif defined(__GNUC__)
61+
62+
#define TEMPEST_CURRENT_SOURCE_LOCATION() \
63+
::tempest::source_location::source_location(__builtin_LINE(), __builtin_COLUMN(), __builtin_FILE(), \
64+
__PRETTY_FUNCTION__)
65+
66+
#endif
67+
7968
#endif // tempest_core_source_location_hpp

projects/math/tests/mat4_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using tempest::math::mat4;
77
using tempest::math::vec4;
88

9-
TEST(Mat4F, DefaultConstructor)
9+
TEST(Mat4F, ZeroInit)
1010
{
11-
mat4<float> m;
11+
mat4<float> m{};
1212

1313
ASSERT_FLOAT_EQ(m[0][0], 0.0f);
1414
ASSERT_FLOAT_EQ(m[0][1], 0.0f);

0 commit comments

Comments
 (0)