|
1 | | -// -*- C++ -*- |
2 | | -//===----------------------------------------------------------------------===// |
3 | | -// |
4 | | -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | | -// See https://llvm.org/LICENSE.txt for license information. |
6 | | -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | | -// |
8 | | -//===----------------------------------------------------------------------===// |
9 | | - |
10 | | -#ifndef _EZCXX_SOURCE_LOCATION |
11 | | -#define _EZCXX_SOURCE_LOCATION |
12 | | - |
13 | | -#include <__config> |
14 | | -#include <cstdint> |
15 | | - |
16 | | -#pragma clang system_header |
17 | | - |
18 | | -namespace std { |
19 | | - |
20 | | -class source_location { |
21 | | - // The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column |
22 | | - // are hard-coded in the compiler and must not be changed here. |
23 | | - struct __impl { |
24 | | - const char* _M_file_name; |
25 | | - const char* _M_function_name; |
26 | | - unsigned _M_line; |
27 | | - unsigned _M_column; |
28 | | - }; |
29 | | - const __impl* __ptr_ = nullptr; |
30 | | - // GCC returns the type 'const void*' from the builtin, while clang returns |
31 | | - // `const __impl*`. Per C++ [expr.const], casts from void* are not permitted |
32 | | - // in constant evaluation, so we don't want to use `void*` as the argument |
33 | | - // type unless the builtin returned that, anyhow, and the invalid cast is |
34 | | - // unavoidable. |
35 | | - using __bsl_ty _EZCXX_NODEBUG = decltype(__builtin_source_location()); |
36 | | - |
37 | | -public: |
38 | | - // The defaulted __ptr argument is necessary so that the builtin is evaluated |
39 | | - // in the context of the caller. An explicit value should never be provided. |
40 | | - static consteval source_location current(__bsl_ty __ptr = __builtin_source_location()) noexcept { |
41 | | - source_location __sl; |
42 | | - __sl.__ptr_ = static_cast<const __impl*>(__ptr); |
43 | | - return __sl; |
44 | | - } |
45 | | - _EZCXX_HIDE_FROM_ABI constexpr source_location() noexcept = default; |
46 | | - |
47 | | - _EZCXX_HIDE_FROM_ABI constexpr uint_least32_t line() const noexcept { |
48 | | - return __ptr_ != nullptr ? __ptr_->_M_line : 0; |
49 | | - } |
50 | | - _EZCXX_HIDE_FROM_ABI constexpr uint_least32_t column() const noexcept { |
51 | | - return __ptr_ != nullptr ? __ptr_->_M_column : 0; |
52 | | - } |
53 | | - _EZCXX_HIDE_FROM_ABI constexpr const char* file_name() const noexcept { |
54 | | - return __ptr_ != nullptr ? __ptr_->_M_file_name : ""; |
55 | | - } |
56 | | - _EZCXX_HIDE_FROM_ABI constexpr const char* function_name() const noexcept { |
57 | | - return __ptr_ != nullptr ? __ptr_->_M_function_name : ""; |
58 | | - } |
59 | | -}; |
60 | | - |
61 | | -} // namespace std |
62 | | - |
63 | | -#endif // _EZCXX_SOURCE_LOCATION |
| 1 | +// -*- C++ -*- |
| 2 | +//===----------------------------------------------------------------------===// |
| 3 | +// |
| 4 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | +// See https://llvm.org/LICENSE.txt for license information. |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +#ifndef _EZCXX_SOURCE_LOCATION |
| 11 | +#define _EZCXX_SOURCE_LOCATION |
| 12 | + |
| 13 | +#include <__config> |
| 14 | +#include <cstdint> |
| 15 | + |
| 16 | +#pragma clang system_header |
| 17 | + |
| 18 | +namespace std { |
| 19 | + |
| 20 | +class source_location { |
| 21 | + // The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column |
| 22 | + // are hard-coded in the compiler and must not be changed here. |
| 23 | + struct __impl { |
| 24 | + const char* _M_file_name; |
| 25 | + const char* _M_function_name; |
| 26 | + unsigned _M_line; |
| 27 | + unsigned _M_column; |
| 28 | + }; |
| 29 | + const __impl* __ptr_ = nullptr; |
| 30 | + // GCC returns the type 'const void*' from the builtin, while clang returns |
| 31 | + // `const __impl*`. Per C++ [expr.const], casts from void* are not permitted |
| 32 | + // in constant evaluation, so we don't want to use `void*` as the argument |
| 33 | + // type unless the builtin returned that, anyhow, and the invalid cast is |
| 34 | + // unavoidable. |
| 35 | + using __bsl_ty _EZCXX_NODEBUG = decltype(__builtin_source_location()); |
| 36 | + |
| 37 | +public: |
| 38 | + // The defaulted __ptr argument is necessary so that the builtin is evaluated |
| 39 | + // in the context of the caller. An explicit value should never be provided. |
| 40 | + static consteval source_location current(__bsl_ty __ptr = __builtin_source_location()) noexcept { |
| 41 | + source_location __sl; |
| 42 | + __sl.__ptr_ = static_cast<const __impl*>(__ptr); |
| 43 | + return __sl; |
| 44 | + } |
| 45 | + _EZCXX_HIDE_FROM_ABI constexpr source_location() noexcept = default; |
| 46 | + |
| 47 | + _EZCXX_HIDE_FROM_ABI constexpr uint_least32_t line() const noexcept { |
| 48 | + return __ptr_ != nullptr ? __ptr_->_M_line : 0; |
| 49 | + } |
| 50 | + _EZCXX_HIDE_FROM_ABI constexpr uint_least32_t column() const noexcept { |
| 51 | + return __ptr_ != nullptr ? __ptr_->_M_column : 0; |
| 52 | + } |
| 53 | + _EZCXX_HIDE_FROM_ABI constexpr const char* file_name() const noexcept { |
| 54 | + return __ptr_ != nullptr ? __ptr_->_M_file_name : ""; |
| 55 | + } |
| 56 | + _EZCXX_HIDE_FROM_ABI constexpr const char* function_name() const noexcept { |
| 57 | + return __ptr_ != nullptr ? __ptr_->_M_function_name : ""; |
| 58 | + } |
| 59 | +}; |
| 60 | + |
| 61 | +} // namespace std |
| 62 | + |
| 63 | +#endif // _EZCXX_SOURCE_LOCATION |
0 commit comments