aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-05-16 14:37:52 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2017-05-16 14:37:52 +0100
commit2673bae9d22a343c2df4cb635b818956b95ff1cf (patch)
tree03a60b4ca33d9a963f044403796a0817a8882b5a
parent423624979a496c1e2755f538b1cf54736a0f449e (diff)
downloadgcc-2673bae9d22a343c2df4cb635b818956b95ff1cf.zip
gcc-2673bae9d22a343c2df4cb635b818956b95ff1cf.tar.gz
gcc-2673bae9d22a343c2df4cb635b818956b95ff1cf.tar.bz2
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
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/doc/html/manual/status.html4
-rw-r--r--libstdc++-v3/doc/xml/manual/status_cxx2017.xml3
-rw-r--r--libstdc++-v3/include/Makefile.am1
-rw-r--r--libstdc++-v3/include/Makefile.in1
-rw-r--r--libstdc++-v3/include/experimental/source_location86
-rw-r--r--libstdc++-v3/testsuite/experimental/source_location/1.cc117
7 files changed, 216 insertions, 4 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 8926b93..5cc498b 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,13 @@
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.
diff --git a/libstdc++-v3/doc/html/manual/status.html b/libstdc++-v3/doc/html/manual/status.html
index 4d293cb..c3b6201 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -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>
diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
index 0e35f75..a208238 100644
--- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
+++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml
@@ -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>
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 3703bd1..a651736 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -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 \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index ae1481f..783c647 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -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 \
diff --git a/libstdc++-v3/include/experimental/source_location b/libstdc++-v3/include/experimental/source_location
new file mode 100644
index 0000000..b06d8b6
--- /dev/null
+++ b/libstdc++-v3/include/experimental/source_location
@@ -0,0 +1,86 @@
+// <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
diff --git a/libstdc++-v3/testsuite/experimental/source_location/1.cc b/libstdc++-v3/testsuite/experimental/source_location/1.cc
new file mode 100644
index 0000000..2634ab4
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/source_location/1.cc
@@ -0,0 +1,117 @@
+// 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();
+}