Commit 2673bae9 by Jonathan Wakely Committed by Jonathan Wakely

Implement std::experimental::source_location (N4519)

	* configure: Regenerate.
	* doc/xml/manual/status_cxx2017.xml: Update status table.
	* doc/html/*: Regenerate.
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/experimental/source_location: New header implementing N4519.
	* testsuite/experimental/source_location/1.cc: New test.

From-SVN: r248110
parent 42362497
2017-05-16 Jonathan Wakely <jwakely@redhat.com>
* configure: Regenerate.
* doc/xml/manual/status_cxx2017.xml: Update status table.
* doc/html/*: Regenerate.
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/experimental/source_location: New header implementing N4519.
* testsuite/experimental/source_location/1.cc: New test.
PR libstdc++/80285
* include/bits/shared_ptr_base.h [!__cpp_rtti] (type_info): Declare
outside versioned namespace.
......
......@@ -824,11 +824,11 @@ Feature-testing recommendations for C++</a>.
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf" target="_top">
N4502
</a>
</td><td align="left"> Support for the C++ Detection Idiom, V2 </td><td align="left">Y</td><td align="left">Library Fundamentals 2 TS</td></tr><tr bgcolor="#C8B0B0"><td align="left">
</td><td align="left"> Support for the C++ Detection Idiom, V2 </td><td align="left">Y</td><td align="left">Library Fundamentals 2 TS</td></tr><tr><td align="left">
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4519.pdf" target="_top">
N4519
</a>
</td><td align="left"> Source-Code Information Capture </td><td align="left">N</td><td align="left">Library Fundamentals 2 TS</td></tr><tr bgcolor="#C8B0B0"><td align="left">
</td><td align="left"> Source-Code Information Capture </td><td align="left">Y</td><td align="left">Library Fundamentals 2 TS</td></tr><tr bgcolor="#C8B0B0"><td align="left">
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4521.html" target="_top">
N4521
</a>
......
......@@ -878,14 +878,13 @@ Feature-testing recommendations for C++</link>.
</row>
<row>
<?dbhtml bgcolor="#C8B0B0" ?>
<entry>
<link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4519.pdf">
N4519
</link>
</entry>
<entry> Source-Code Information Capture </entry>
<entry>N</entry>
<entry>Y</entry>
<entry>Library Fundamentals 2 TS</entry>
</row>
......
......@@ -679,6 +679,7 @@ experimental_headers = \
${experimental_srcdir}/ratio \
${experimental_srcdir}/regex \
${experimental_srcdir}/set \
${experimental_srcdir}/source_location \
${experimental_srcdir}/string \
${experimental_srcdir}/string_view \
${experimental_srcdir}/system_error \
......
......@@ -971,6 +971,7 @@ experimental_headers = \
${experimental_srcdir}/ratio \
${experimental_srcdir}/regex \
${experimental_srcdir}/set \
${experimental_srcdir}/source_location \
${experimental_srcdir}/string \
${experimental_srcdir}/string_view \
${experimental_srcdir}/system_error \
......
// <experimental/source_location> -*- C++ -*-
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file experimental/source_location
* This is a TS C++ Library header.
*/
#ifndef _GLIBCXX_EXPERIMENTAL_SRCLOC
#define _GLIBCXX_EXPERIMENTAL_SRCLOC 1
#include <cstdint>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#define __cpp_lib_experimental_source_location 201505
struct source_location
{
#ifndef _GLIBCXX_USE_C99_STDINT_TR1
private:
using uint_least32_t = unsigned;
public:
#endif
// 14.1.2, source_location creation
static constexpr source_location
current(const char* __file = __builtin_FILE(),
const char* __func = __builtin_FUNCTION(),
int __line = __builtin_LINE(),
int __col = 0) noexcept
{
source_location __loc;
__loc._M_file = __file;
__loc._M_func = __func;
__loc._M_line = __line;
__loc._M_col = __col;
return __loc;
}
constexpr source_location() noexcept
: _M_file("unknown"), _M_func(_M_file), _M_line(0), _M_col(0)
{ }
// 14.1.3, source_location field access
constexpr uint_least32_t line() const noexcept { return _M_line; }
constexpr uint_least32_t column() const noexcept { return _M_col; }
constexpr const char* file_name() const noexcept { return _M_file; }
constexpr const char* function_name() const noexcept { return _M_func; }
private:
const char* _M_file;
const char* _M_func;
uint_least32_t _M_line;
uint_least32_t _M_col;
};
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace fundamentals_v2
} // namespace experimental
} // namespace std
#endif
// Copyright (C) 2017 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-do run { target c++14 } }
#include <experimental/source_location>
#include <experimental/string_view>
#include <testsuite_hooks.h>
using std::experimental::source_location;
using std::experimental::string_view;
void
test01()
{
constexpr source_location loc = source_location::current();
static_assert( loc.line() == 30 );
// static_assert( loc.column() == 35 );
VERIFY( loc.file_name() == __FILE__ );
VERIFY( loc.function_name() == string_view(__FUNCTION__) );
}
struct S {
string_view func;
source_location loc = source_location::current();
S(source_location loc = source_location::current())
: func(__FUNCTION__), loc(loc) // values of loc will be from call-site
{}
S(int)
: func(__FUNCTION__) // values of loc should be hereabouts
{}
};
void test02()
{
S s0;
VERIFY( s0.loc.line() == 52 );
// static_assert( s0.loc.column() == 7 );
VERIFY( s0.loc.file_name() == __FILE__ );
VERIFY( s0.loc.function_name() == string_view(__FUNCTION__) );
S s1(1);
VERIFY( s1.loc.line() != 58 );
VERIFY( s1.loc.file_name() == __FILE__ );
// VERIFY( s1.loc.function_name() == s1.func );
}
source_location f(source_location a = source_location::current()) {
return a;
}
source_location g(string_view& func) {
source_location a = source_location::current();
func = __FUNCTION__;
return a;
}
void test03()
{
auto loc = f(); // f's first argument corresponds to this line of code
VERIFY( loc.line() == 76 );
// static_assert( loc.column() == 16 );
VERIFY( loc.file_name() == __FILE__ );
VERIFY( loc.function_name() == string_view(__FUNCTION__) );
source_location c = source_location::current();
loc = f(c); // f's first argument gets the same values as c, above
VERIFY( loc.line() == 82 );
// static_assert( loc.column() == 23 );
VERIFY( loc.file_name() == __FILE__ );
VERIFY( loc.function_name() == string_view(__FUNCTION__) );
string_view func;
loc = g(func);
VERIFY( loc.line() == 69 );
// static_assert( loc.column() == 23 );
VERIFY( loc.file_name() == __FILE__ );
VERIFY( loc.function_name() == func );
}
void
test04()
{
using std::is_same;
using std::uint_least32_t;
auto loc = source_location::current();
static_assert(is_same<decltype(loc), source_location>::value, "");
static_assert(is_same<decltype(loc.line()), uint_least32_t>::value, "");
static_assert(is_same<decltype(loc.column()), uint_least32_t>::value, "");
static_assert(is_same<decltype(loc.file_name()), const char*>::value, "");
static_assert(is_same<decltype(loc.function_name()), const char*>::value, "");
}
int
main()
{
test01();
test02();
test03();
test04();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment