Warning, /include/c++/v1/source_location is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP_SOURCE_LOCATION
0011 #define _LIBCPP_SOURCE_LOCATION
0012
0013 /* source_location synopsis
0014
0015 namespace std {
0016 struct source_location {
0017 static consteval source_location current() noexcept;
0018 constexpr source_location() noexcept;
0019
0020 constexpr uint_least32_t line() const noexcept;
0021 constexpr uint_least32_t column() const noexcept;
0022 constexpr const char* file_name() const noexcept;
0023 constexpr const char* function_name() const noexcept;
0024 };
0025 }
0026 */
0027
0028 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0029 # include <__cxx03/source_location>
0030 #else
0031 # include <__config>
0032 # include <cstdint>
0033 # include <version>
0034
0035 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0036 # pragma GCC system_header
0037 # endif
0038
0039 _LIBCPP_BEGIN_NAMESPACE_STD
0040
0041 # if _LIBCPP_STD_VER >= 20
0042
0043 class source_location {
0044 // The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column
0045 // are hard-coded in the compiler and must not be changed here.
0046 struct __impl {
0047 const char* _M_file_name;
0048 const char* _M_function_name;
0049 unsigned _M_line;
0050 unsigned _M_column;
0051 };
0052 const __impl* __ptr_ = nullptr;
0053 // GCC returns the type 'const void*' from the builtin, while clang returns
0054 // `const __impl*`. Per C++ [expr.const], casts from void* are not permitted
0055 // in constant evaluation, so we don't want to use `void*` as the argument
0056 // type unless the builtin returned that, anyhow, and the invalid cast is
0057 // unavoidable.
0058 using __bsl_ty _LIBCPP_NODEBUG = decltype(__builtin_source_location());
0059
0060 public:
0061 // The defaulted __ptr argument is necessary so that the builtin is evaluated
0062 // in the context of the caller. An explicit value should never be provided.
0063 static consteval source_location current(__bsl_ty __ptr = __builtin_source_location()) noexcept {
0064 source_location __sl;
0065 __sl.__ptr_ = static_cast<const __impl*>(__ptr);
0066 return __sl;
0067 }
0068 _LIBCPP_HIDE_FROM_ABI constexpr source_location() noexcept = default;
0069
0070 _LIBCPP_HIDE_FROM_ABI constexpr uint_least32_t line() const noexcept {
0071 return __ptr_ != nullptr ? __ptr_->_M_line : 0;
0072 }
0073 _LIBCPP_HIDE_FROM_ABI constexpr uint_least32_t column() const noexcept {
0074 return __ptr_ != nullptr ? __ptr_->_M_column : 0;
0075 }
0076 _LIBCPP_HIDE_FROM_ABI constexpr const char* file_name() const noexcept {
0077 return __ptr_ != nullptr ? __ptr_->_M_file_name : "";
0078 }
0079 _LIBCPP_HIDE_FROM_ABI constexpr const char* function_name() const noexcept {
0080 return __ptr_ != nullptr ? __ptr_->_M_function_name : "";
0081 }
0082 };
0083
0084 # endif // _LIBCPP_STD_VER >= 20
0085
0086 _LIBCPP_END_NAMESPACE_STD
0087
0088 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0089
0090 #endif // _LIBCPP_SOURCE_LOCATION