1*b1e83836Smrg// <source_location> -*- C++ -*- 2*b1e83836Smrg 3*b1e83836Smrg// Copyright (C) 2020-2022 Free Software Foundation, Inc. 4*b1e83836Smrg// 5*b1e83836Smrg// This file is part of the GNU ISO C++ Library. This library is free 6*b1e83836Smrg// software; you can redistribute it and/or modify it under the 7*b1e83836Smrg// terms of the GNU General Public License as published by the 8*b1e83836Smrg// Free Software Foundation; either version 3, or (at your option) 9*b1e83836Smrg// any later version. 10*b1e83836Smrg 11*b1e83836Smrg// This library is distributed in the hope that it will be useful, 12*b1e83836Smrg// but WITHOUT ANY WARRANTY; without even the implied warranty of 13*b1e83836Smrg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*b1e83836Smrg// GNU General Public License for more details. 15*b1e83836Smrg 16*b1e83836Smrg// Under Section 7 of GPL version 3, you are granted additional 17*b1e83836Smrg// permissions described in the GCC Runtime Library Exception, version 18*b1e83836Smrg// 3.1, as published by the Free Software Foundation. 19*b1e83836Smrg 20*b1e83836Smrg// You should have received a copy of the GNU General Public License and 21*b1e83836Smrg// a copy of the GCC Runtime Library Exception along with this program; 22*b1e83836Smrg// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*b1e83836Smrg// <http://www.gnu.org/licenses/>. 24*b1e83836Smrg 25*b1e83836Smrg/** @file include/source_location 26*b1e83836Smrg * This is a Standard C++ Library header. 27*b1e83836Smrg */ 28*b1e83836Smrg 29*b1e83836Smrg#ifndef _GLIBCXX_SRCLOC 30*b1e83836Smrg#define _GLIBCXX_SRCLOC 1 31*b1e83836Smrg 32*b1e83836Smrg#if __cplusplus > 201703L && __has_builtin(__builtin_source_location) 33*b1e83836Smrg#include <bits/c++config.h> 34*b1e83836Smrg 35*b1e83836Smrgnamespace std 36*b1e83836Smrg{ 37*b1e83836Smrg_GLIBCXX_BEGIN_NAMESPACE_VERSION 38*b1e83836Smrg 39*b1e83836Smrg#define __cpp_lib_source_location 201907L 40*b1e83836Smrg 41*b1e83836Smrg /// A class that describes a location in source code. 42*b1e83836Smrg struct source_location 43*b1e83836Smrg { 44*b1e83836Smrg private: 45*b1e83836Smrg using uint_least32_t = __UINT_LEAST32_TYPE__; 46*b1e83836Smrg struct __impl 47*b1e83836Smrg { 48*b1e83836Smrg const char* _M_file_name; 49*b1e83836Smrg const char* _M_function_name; 50*b1e83836Smrg unsigned _M_line; 51*b1e83836Smrg unsigned _M_column; 52*b1e83836Smrg }; 53*b1e83836Smrg using __builtin_ret_type = decltype(__builtin_source_location()); 54*b1e83836Smrg 55*b1e83836Smrg public: 56*b1e83836Smrg 57*b1e83836Smrg // [support.srcloc.cons], creation 58*b1e83836Smrg static consteval source_location 59*b1e83836Smrg current(__builtin_ret_type __p = __builtin_source_location()) noexcept 60*b1e83836Smrg { 61*b1e83836Smrg source_location __ret; 62*b1e83836Smrg __ret._M_impl = static_cast <const __impl*>(__p); 63*b1e83836Smrg return __ret; 64*b1e83836Smrg } 65*b1e83836Smrg 66*b1e83836Smrg constexpr source_location() noexcept { } 67*b1e83836Smrg 68*b1e83836Smrg // [support.srcloc.obs], observers 69*b1e83836Smrg constexpr uint_least32_t 70*b1e83836Smrg line() const noexcept 71*b1e83836Smrg { return _M_impl ? _M_impl->_M_line : 0u; } 72*b1e83836Smrg 73*b1e83836Smrg constexpr uint_least32_t 74*b1e83836Smrg column() const noexcept 75*b1e83836Smrg { return _M_impl ? _M_impl->_M_column : 0u; } 76*b1e83836Smrg 77*b1e83836Smrg constexpr const char* 78*b1e83836Smrg file_name() const noexcept 79*b1e83836Smrg { return _M_impl ? _M_impl->_M_file_name : ""; } 80*b1e83836Smrg 81*b1e83836Smrg constexpr const char* 82*b1e83836Smrg function_name() const noexcept 83*b1e83836Smrg { return _M_impl ? _M_impl->_M_function_name : ""; } 84*b1e83836Smrg 85*b1e83836Smrg private: 86*b1e83836Smrg const __impl* _M_impl = nullptr; 87*b1e83836Smrg }; 88*b1e83836Smrg 89*b1e83836Smrg_GLIBCXX_END_NAMESPACE_VERSION 90*b1e83836Smrg} // namespace std 91*b1e83836Smrg#endif // C++20 && __builtin_source_location 92*b1e83836Smrg#endif // _GLIBCXX_SRCLOC 93