On 16/05/17 14:40 +0100, Jonathan Wakely wrote:
This is a partial implementation of <experimental/source_location>,
see the commented-out lines in the testcase for the missing pieces.
I'll be opening a PR to get the needed front-end support complete it.
That's https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80780
+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 );
I thought we didn't get the right location when current() is used in a
default member initializer, but we do, so this part of the test can be
uncommented. The implementation is more complete than I realised :-)
Tested x86_64-linux, committed to trunk.
commit 546efe296150b8e7db9e8c3287e19648c1736193
Author: Jonathan Wakely <jwak...@redhat.com>
Date: Tue May 16 15:18:29 2017 +0100
Test source_location::current() in default member initializer
* testsuite/experimental/source_location/1.cc: Change expected result
for source_location::current() used in default member initializer.
diff --git a/libstdc++-v3/testsuite/experimental/source_location/1.cc b/libstdc++-v3/testsuite/experimental/source_location/1.cc
index 2634ab4..febd84e 100644
--- a/libstdc++-v3/testsuite/experimental/source_location/1.cc
+++ b/libstdc++-v3/testsuite/experimental/source_location/1.cc
@@ -56,9 +56,9 @@ void test02()
VERIFY( s0.loc.function_name() == string_view(__FUNCTION__) );
S s1(1);
- VERIFY( s1.loc.line() != 58 );
+ VERIFY( s1.loc.line() == 46 );
VERIFY( s1.loc.file_name() == __FILE__ );
- // VERIFY( s1.loc.function_name() == s1.func );
+ VERIFY( s1.loc.function_name() == s1.func );
}
source_location f(source_location a = source_location::current()) {