Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/__cxx03/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___CXX03_SOURCE_LOCATION
0011 #define _LIBCPP___CXX03_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 #include <__cxx03/__config>
0029 #include <__cxx03/cstdint>
0030 #include <__cxx03/version>
0031 
0032 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0033 #  pragma GCC system_header
0034 #endif
0035 
0036 _LIBCPP_BEGIN_NAMESPACE_STD
0037 
0038 #if _LIBCPP_STD_VER >= 20
0039 
0040 class source_location {
0041   // The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column
0042   // are hard-coded in the compiler and must not be changed here.
0043   struct __impl {
0044     const char* _M_file_name;
0045     const char* _M_function_name;
0046     unsigned _M_line;
0047     unsigned _M_column;
0048   };
0049   const __impl* __ptr_ = nullptr;
0050   // GCC returns the type 'const void*' from the builtin, while clang returns
0051   // `const __impl*`. Per C++ [expr.const], casts from void* are not permitted
0052   // in constant evaluation, so we don't want to use `void*` as the argument
0053   // type unless the builtin returned that, anyhow, and the invalid cast is
0054   // unavoidable.
0055   using __bsl_ty = decltype(__builtin_source_location());
0056 
0057 public:
0058   // The defaulted __ptr argument is necessary so that the builtin is evaluated
0059   // in the context of the caller. An explicit value should never be provided.
0060   static consteval source_location current(__bsl_ty __ptr = __builtin_source_location()) noexcept {
0061     source_location __sl;
0062     __sl.__ptr_ = static_cast<const __impl*>(__ptr);
0063     return __sl;
0064   }
0065   _LIBCPP_HIDE_FROM_ABI constexpr source_location() noexcept = default;
0066 
0067   _LIBCPP_HIDE_FROM_ABI constexpr uint_least32_t line() const noexcept {
0068     return __ptr_ != nullptr ? __ptr_->_M_line : 0;
0069   }
0070   _LIBCPP_HIDE_FROM_ABI constexpr uint_least32_t column() const noexcept {
0071     return __ptr_ != nullptr ? __ptr_->_M_column : 0;
0072   }
0073   _LIBCPP_HIDE_FROM_ABI constexpr const char* file_name() const noexcept {
0074     return __ptr_ != nullptr ? __ptr_->_M_file_name : "";
0075   }
0076   _LIBCPP_HIDE_FROM_ABI constexpr const char* function_name() const noexcept {
0077     return __ptr_ != nullptr ? __ptr_->_M_function_name : "";
0078   }
0079 };
0080 
0081 #endif // _LIBCPP_STD_VER >= 20
0082 
0083 _LIBCPP_END_NAMESPACE_STD
0084 
0085 #endif // _LIBCPP___CXX03_SOURCE_LOCATION