Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7e06756
Implement <source_location>
SuperWig Mar 31, 2020
38d9d9f
Combine calling and argument
SuperWig Mar 31, 2020
8534478
Use __LINE__
SuperWig Mar 31, 2020
5dd4281
Make global global
SuperWig Mar 31, 2020
da69f62
Add license banner to header.h
SuperWig Apr 1, 2020
90f321c
Add _NODISCARD to source_location::current()
SuperWig Apr 1, 2020
f0a692d
Copyright is probably important...
SuperWig Apr 3, 2020
a441e77
Add NTTP test
SuperWig Apr 3, 2020
4bf3253
Fix sub_member_test()
SuperWig Apr 7, 2020
1699518
Remove nttp_test()
SuperWig Apr 7, 2020
6b64f6c
Missing constexpr
SuperWig Apr 10, 2020
3c895e7
Only support clang
SuperWig Apr 29, 2020
d3f4c9e
&& not ||
SuperWig Apr 29, 2020
8520e74
Merge remote-tracking branch 'origin/master' into source_location
SuperWig Apr 29, 2020
e9e18a7
Update feature_test_macro test
SuperWig Apr 29, 2020
790bf20
Update __msvc_all_public_headers.hpp
SuperWig Apr 29, 2020
5aa751b
Revert "&& not ||"
SuperWig Apr 29, 2020
b26b5c8
Revert "Update __msvc_all_public_headers.hpp"
SuperWig Apr 29, 2020
4e2d9b8
Review comments
SuperWig Apr 29, 2020
0d9d103
Casey's guard
SuperWig Apr 29, 2020
8f0cfec
Update source_location part 1
SuperWig Apr 30, 2020
26d1ddc
Update source_location part 2
SuperWig Apr 30, 2020
a9531db
__cpp_consteval
SuperWig Apr 30, 2020
1665637
Transition, const, and unsigned int
SuperWig Apr 30, 2020
92f16ae
Missed two __cpp_consteval
SuperWig May 6, 2020
ce6b054
Merge branch 'master' into source_location
SuperWig Jul 18, 2020
6f03c28
Merge branch 'main' into source_location
StephanTLavavej Feb 27, 2021
9aeb14d
Add source_location to various lists of files.
StephanTLavavej Feb 28, 2021
7dd96df
__msvc_all_public_headers.hpp now has core/non-core sections.
StephanTLavavej Feb 28, 2021
ffad77c
Sort VSO_0157762_feature_test_macros.
StephanTLavavej Feb 28, 2021
0e6a025
Note apparent bugs in MSVC 16.10p2.
StephanTLavavej Feb 28, 2021
b6cc086
Work around VSO-1285779 'EDG rejects source_location intrinsics withi…
StephanTLavavej Mar 1, 2021
8f88b17
Reported VSO-1285783 'C++20 source_location intrinsic __builtin_FUNCT…
StephanTLavavej Mar 1, 2021
723991a
Column numbers are reasonable. Add comma to TRANSITION.
StephanTLavavej Mar 1, 2021
66324e1
Test source_location in P1502R1_standard_library_header_units.
StephanTLavavej Mar 1, 2021
0183fb4
Use only filenames; internal Contest copies to different directories.
StephanTLavavej Mar 1, 2021
2a81652
/analyze expects different column numbers.
StephanTLavavej Mar 1, 2021
c3cd3fa
yvals_core.h: Comment endif.
StephanTLavavej Mar 1, 2021
adaeb5d
Add MSVC to include_each_header_alone_matrix.lst.
StephanTLavavej Mar 1, 2021
e10b9d8
source_location: Stylistic changes.
StephanTLavavej Mar 1, 2021
1521789
Test style: Avoid depending on header.h's includes and using-directive.
StephanTLavavej Mar 1, 2021
4cd0c85
Test style: Terse static_assert is fine.
StephanTLavavej Mar 1, 2021
5aec486
We can also test is_nothrow_default_constructible_v.
StephanTLavavej Mar 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ set(HEADERS
${CMAKE_CURRENT_LIST_DIR}/inc/semaphore
${CMAKE_CURRENT_LIST_DIR}/inc/set
${CMAKE_CURRENT_LIST_DIR}/inc/shared_mutex
${CMAKE_CURRENT_LIST_DIR}/inc/source_location
${CMAKE_CURRENT_LIST_DIR}/inc/span
${CMAKE_CURRENT_LIST_DIR}/inc/sstream
${CMAKE_CURRENT_LIST_DIR}/inc/stack
Expand Down
1 change: 1 addition & 0 deletions stl/inc/__msvc_all_public_headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <limits>
#include <numbers>
#include <ratio>
#include <source_location>
#include <type_traits>
#include <utility>
#include <version>
Expand Down
1 change: 1 addition & 0 deletions stl/inc/header-units.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"semaphore",
"set",
"shared_mutex",
"source_location",
"span",
"sstream",
"stack",
Expand Down
66 changes: 66 additions & 0 deletions stl/inc/source_location
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// source_location standard header (core)

// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#pragma once
#ifndef _SOURCE_LOCATION_
#define _SOURCE_LOCATION_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR
#ifndef __cpp_consteval
#pragma message("The contents of <source_location> are available only with C++20 consteval support.")
#else // ^^^ !defined(__cpp_consteval) / defined(__cpp_consteval) vvv

#include <cstdint>

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

_STD_BEGIN
struct source_location {
_NODISCARD static consteval source_location current(const uint_least32_t _Line_ = __builtin_LINE(),
const uint_least32_t _Column_ = __builtin_COLUMN(), const char* const _File_ = __builtin_FILE(),
const char* const _Function_ = __builtin_FUNCTION()) noexcept {
source_location _Result;
_Result._Line = _Line_;
_Result._Column = _Column_;
_Result._File = _File_;
_Result._Function = _Function_;
return _Result;
}

_NODISCARD_CTOR constexpr source_location() noexcept = default;

_NODISCARD constexpr uint_least32_t line() const noexcept {
return _Line;
}
_NODISCARD constexpr uint_least32_t column() const noexcept {
return _Column;
}
_NODISCARD constexpr const char* file_name() const noexcept {
return _File;
}
_NODISCARD constexpr const char* function_name() const noexcept {
return _Function;
}

private:
uint_least32_t _Line{};
uint_least32_t _Column{};
const char* _File = "";
const char* _Function = "";
};
_STD_END

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
#pragma pack(pop)
#endif // !defined(__cpp_consteval)
#endif // _STL_COMPILER_PREPROCESSOR
#endif // _SOURCE_LOCATION_
14 changes: 10 additions & 4 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
// P1135R6 The C++20 Synchronization Library
// P1207R4 Movability Of Single-Pass Iterators
// (partially implemented)
// P1208R6 <source_location>
// P1209R0 erase_if(), erase()
// P1227R2 Signed std::ssize(), Unsigned span::size()
// P1243R4 Rangify New Algorithms
Expand Down Expand Up @@ -1255,10 +1256,15 @@
#define __cpp_lib_semaphore 201907L
#define __cpp_lib_shift 201806L
#define __cpp_lib_smart_ptr_for_overwrite 202002L
#define __cpp_lib_span 202002L
#define __cpp_lib_ssize 201902L
#define __cpp_lib_starts_ends_with 201711L
#define __cpp_lib_syncbuf 201803L

#ifdef __cpp_consteval
#define __cpp_lib_source_location 201907L
#endif // __cpp_consteval

#define __cpp_lib_span 202002L
#define __cpp_lib_ssize 201902L
#define __cpp_lib_starts_ends_with 201711L
#define __cpp_lib_syncbuf 201803L

#ifdef __cpp_lib_concepts // TRANSITION, GH-395
#define __cpp_lib_three_way_comparison 201907L
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ tests\P1135R6_barrier
tests\P1135R6_latch
tests\P1135R6_semaphore
tests\P1165R1_consistently_propagating_stateful_allocators
tests\P1208R6_source_location
tests\P1423R3_char8_t_remediation
tests\P1502R1_standard_library_header_units
tests\P1614R2_spaceship
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P1208R6_source_location/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_latest_matrix.lst
16 changes: 16 additions & 0 deletions tests/std/tests/P1208R6_source_location/header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#pragma once
#include <cassert>
#include <source_location>
#include <string_view>

constexpr void header_test() {
using namespace std;
const auto x = source_location::current();
assert(x.line() == __LINE__ - 1);
assert(x.column() == 37);
assert(x.function_name() == "header_test"sv);
assert(string_view{x.file_name()}.ends_with("header.h"sv));
}
160 changes: 160 additions & 0 deletions tests/std/tests/P1208R6_source_location/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#if defined(__cpp_consteval) && !defined(__EDG__) // TRANSITION, VSO-1285779
#include "header.h"
#include <cassert>
#include <source_location>
#include <string_view>
#include <type_traits>
using namespace std;

static_assert(is_nothrow_default_constructible_v<source_location>);
static_assert(is_nothrow_move_constructible_v<source_location>);
static_assert(is_nothrow_move_assignable_v<source_location>);
static_assert(is_nothrow_swappable_v<source_location>);

constexpr auto test_cpp = "test.cpp"sv;

constexpr auto g = source_location::current();
static_assert(g.line() == __LINE__ - 1);
static_assert(g.column() == 37);
static_assert(g.function_name() == ""sv);
static_assert(string_view{g.file_name()}.ends_with(test_cpp));

constexpr int s_int_line = __LINE__ + 3;
struct s {
constexpr s(const source_location x = source_location::current()) : loc(x) {}
constexpr s(int) {}
source_location loc = source_location::current();
};

constexpr int s2_int_line = __LINE__ + 3;
struct s2 {
constexpr s2(const source_location l = source_location::current()) : x{l} {}
constexpr s2(int) {}
s x = source_location::current();
};

constexpr void copy_test() {
const auto rhs = source_location::current();
const auto lhs = rhs;
assert(lhs.line() == rhs.line());
assert(lhs.column() == rhs.column());
assert(string_view{lhs.function_name()} == string_view{rhs.function_name()});
assert(string_view{lhs.file_name()} == string_view{rhs.file_name()});
}

constexpr void local_test() {
const auto x = source_location::current();
assert(x.line() == __LINE__ - 1);
assert(x.column() == 37);
assert(x.function_name() == "local_test"sv);
assert(string_view{x.file_name()}.ends_with(test_cpp));
}

constexpr void argument_test(
const unsigned int line, const unsigned int column, const source_location x = source_location::current()) {
assert(x.line() == line);
assert(x.column() == column);
assert(x.function_name() == "test"sv);
assert(string_view{x.file_name()}.ends_with(test_cpp));
}

constexpr void sloc_constructor_test() {
const s x;
assert(x.loc.line() == __LINE__ - 1);
#ifdef _PREFAST_
assert(x.loc.column() == 14);
#else // _PREFAST_
assert(x.loc.column() == 13);
#endif // _PREFAST_
if (is_constant_evaluated()) {
assert(x.loc.function_name() == "main"sv); // TRANSITION, VSO-1285783
} else {
assert(x.loc.function_name() == "sloc_constructor_test"sv);
}
assert(string_view{x.loc.file_name()}.ends_with(test_cpp));
}

constexpr void different_constructor_test() {
const s x{1};
assert(x.loc.line() == s_int_line);
assert(x.loc.column() == 5);
assert(x.loc.function_name() == "s"sv);
assert(string_view{x.loc.file_name()}.ends_with(test_cpp));
}

constexpr void sub_member_test() {
const s2 s;
assert(s.x.loc.line() == __LINE__ - 1);
#ifdef _PREFAST_
assert(s.x.loc.column() == 15);
#else // _PREFAST_
assert(s.x.loc.column() == 14);
#endif // _PREFAST_
if (is_constant_evaluated()) {
assert(s.x.loc.function_name() == "main"sv); // TRANSITION, VSO-1285783
} else {
assert(s.x.loc.function_name() == "sub_member_test"sv);
}
assert(string_view{s.x.loc.file_name()}.ends_with(test_cpp));

const s2 s_i{1};
assert(s_i.x.loc.line() == s2_int_line);
assert(s_i.x.loc.column() == 5);
assert(s_i.x.loc.function_name() == "s2"sv);
assert(string_view{s_i.x.loc.file_name()}.ends_with(test_cpp));
}

constexpr void lambda_test() {
const auto l = [loc = source_location::current()] { return loc; };
const auto x = l();
assert(x.line() == __LINE__ - 2);
assert(x.column() == 51);
assert(x.function_name() == "lambda_test"sv);
assert(string_view{x.file_name()}.ends_with(test_cpp));
}

template <class T>
constexpr source_location function_template() {
return source_location::current();
}

constexpr void function_template_test() {
const auto x1 = function_template<void>();
assert(x1.line() == __LINE__ - 5);
assert(x1.column() == 29);
assert(x1.function_name() == "function_template"sv);
assert(string_view{x1.file_name()}.ends_with(test_cpp));

const auto x2 = function_template<int>();
assert(x1.line() == x2.line());
assert(x1.column() == x2.column());
assert(string_view{x1.function_name()} == string_view{x2.function_name()});
assert(string_view{x1.file_name()} == string_view{x2.file_name()});
}

constexpr bool test() {
copy_test();
local_test();
argument_test(__LINE__, 5);
const auto loc = source_location::current();
argument_test(__LINE__ - 1, 39, loc);
sloc_constructor_test();
different_constructor_test();
sub_member_test();
lambda_test();
function_template_test();
header_test();
return true;
}

int main() {
test();
static_assert(test());
return 0;
}
#else // ^^^ defined(__cpp_consteval) && !defined(__EDG__) / !defined(__cpp_consteval) || defined(__EDG__) vvv
int main() {}
#endif // ^^^ !defined(__cpp_consteval) || defined(__EDG__) ^^^
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def getBuildSteps(self, test, litConfig, shared):
'semaphore',
'set',
'shared_mutex',
# 'source_location',
'source_location',
'span',
'sstream',
'stack',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ()
"semaphore",
"set",
"shared_mutex",
# "source_location",
"source_location",
"span",
"sstream",
"stack",
Expand Down
16 changes: 14 additions & 2 deletions tests/std/tests/P1502R1_standard_library_header_units/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import <scoped_allocator>;
import <semaphore>;
import <set>;
import <shared_mutex>;
// import <source_location>;
import <source_location>;
import <span>;
import <sstream>;
import <stack>;
Expand Down Expand Up @@ -94,6 +94,17 @@ import <version>;
#include <force_include.hpp>
using namespace std;

constexpr bool test_source_location() {
#ifdef __cpp_lib_source_location
const auto sl = source_location::current();
assert(sl.line() == __LINE__ - 1);
assert(sl.column() == 1);
assert(sl.function_name() == "test_source_location"sv);
assert(string_view{sl.file_name()}.ends_with("test.cpp"sv));
#endif // __cpp_lib_source_location
return true;
}

int main() {
{
puts("Testing <algorithm>.");
Expand Down Expand Up @@ -689,7 +700,8 @@ int main() {

{
puts("Testing <source_location>.");
puts("(TRANSITION, not yet implemented.)");
assert(test_source_location());
static_assert(test_source_location());
}

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,20 @@ STATIC_ASSERT(__cpp_lib_smart_ptr_for_overwrite == 202002L);
#endif
#endif

#if _HAS_CXX20 && defined(__cpp_consteval)
#ifndef __cpp_lib_source_location
#error __cpp_lib_source_location is not defined
#elif __cpp_lib_source_location != 201907L
#error __cpp_lib_source_location is not 201907L
#else
STATIC_ASSERT(__cpp_lib_source_location == 201907L);
#endif
#else
#ifdef __cpp_lib_source_location
#error __cpp_lib_source_location is defined
#endif
#endif

#if _HAS_CXX20
#ifndef __cpp_lib_span
#error __cpp_lib_span is not defined
Expand Down
Loading