Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
683ef99
Test that selected headers introduce machinery from iterator.range/1
vmichal Dec 19, 2025
c7c0490
Properly guard the test of introduction of begin/end by <optional> by…
vmichal Dec 19, 2025
0d52345
Add tests for hive and inplace_vector.
vmichal Dec 19, 2025
3e32558
Use feature test macro instead of __has_include.
vmichal Dec 19, 2025
a48d2e0
Properly guard tests for C++23 and C++26 feature with feature test ma…
vmichal Dec 19, 2025
8c92460
Properly test the free functions, not member functions.
vmichal Dec 19, 2025
53454ae
Use only feature test macros, do not duplicate the check with _HAS_CXX2a
vmichal Dec 19, 2025
dc2cd24
Add test for <iterator>
vmichal Dec 19, 2025
5b12d07
Fix template utility detecting presence of a member function in conta…
vmichal Jan 3, 2026
dabbeaa
Self test detection mechanism.
vmichal Jan 3, 2026
d13eb55
Rename new tests to mention this GH PR.
vmichal Jan 3, 2026
60a2bf8
Also modify list of tests after renaming the directory
vmichal Jan 4, 2026
3300fd7
Merge branch 'main' into prepare-tests-for-flat-meow
vmichal Jan 9, 2026
2071173
Activate valarray test.
vmichal Jan 8, 2026
c7a20c0
Wrap construction of individual objects into separate scopes to preve…
vmichal Jan 8, 2026
b8abde2
Fix formatting.
vmichal Jan 8, 2026
55904e7
Merge branch 'main' into prepare-tests-for-flat-meow
StephanTLavavej Jan 20, 2026
2b32511
Fix typo: test_literator.cpp => test_iterator.cpp
StephanTLavavej Jan 20, 2026
6c6999c
Update Standard citation.
StephanTLavavej Jan 20, 2026
77d7de8
West const.
StephanTLavavej Jan 20, 2026
2a34cbc
Add `#pragma once`.
StephanTLavavej Jan 20, 2026
9af82e7
typename => class
StephanTLavavej Jan 20, 2026
af14ffa
Fix typo: voi => void
StephanTLavavej Jan 20, 2026
75c7dea
Improve consistency of arrow comments.
StephanTLavavej Jan 20, 2026
2a4faad
Add reminders when implementing features.
StephanTLavavej Jan 20, 2026
77dbd50
Avoid quasi-shadowing: array => arr
StephanTLavavej Jan 20, 2026
76ced32
string_view can directly view "hello".
StephanTLavavej Jan 20, 2026
4dd01ca
Avoid inconsistent use of CTAD for flat_set.
StephanTLavavej Jan 20, 2026
5c3fde2
Don't bother naming unused `t`.
StephanTLavavej Jan 20, 2026
c45cc98
Order rbegin/rend before crbegin/crend.
StephanTLavavej Jan 20, 2026
9702094
Explicitly call out the order assumption.
StephanTLavavej Jan 20, 2026
36aba75
ssize is special.
StephanTLavavej Jan 20, 2026
bf6e064
Always guard ssize for C++20.
StephanTLavavej Jan 20, 2026
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 tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ tests\GH_005546_containers_size_type_cast
tests\GH_005553_regex_character_translation
tests\GH_005768_pow_accuracy
tests\GH_005800_stable_sort_large_alignment
tests\GH_005968_headers_provide_begin_end
tests\LWG2381_num_get_floating_point
tests\LWG2510_tag_classes
tests\LWG2597_complex_branch_cut
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import os

from stl.test.format import STLTestFormat, TestStep
from stl.test.tests import TestType


class CustomTestFormat(STLTestFormat):
def getBuildSteps(self, test, litConfig, shared):
exeSourceDir = os.path.dirname(test.getSourcePath())
_, outputBase = test.getTempPaths()

sourceFiles = []
for filename in os.listdir(exeSourceDir):
if filename.endswith('.cpp'):
sourceFiles.append(os.path.join(exeSourceDir, filename))

if TestType.COMPILE in test.testType:
cmd = [test.cxx, '/c', *sourceFiles, *test.flags, *test.compileFlags]
elif TestType.RUN in test.testType:
shared.execFile = outputBase + '.exe'
cmd = [test.cxx, *sourceFiles, *test.flags, *test.compileFlags, '/Fe' + shared.execFile,
'/link', *test.linkFlags]

yield TestStep(cmd, shared.execDir, shared.env, False)
4 changes: 4 additions & 0 deletions tests/std/tests/GH_005968_headers_provide_begin_end/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_matrix.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import os
import site
site.addsitedir(os.path.dirname(os.path.dirname(__file__)))
import GH_005968_headers_provide_begin_end.custom_format

config.test_format = GH_005968_headers_provide_begin_end.custom_format.CustomTestFormat()
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#pragma once

// Intentionally avoid including anything. Order assumption: shared_test.hpp assumes
// that the relevant Standard headers have already been included by the .cpp files.

// Test requirements of N5032 [iterator.range]/1.

namespace detail {

// file test_iterator.cpp uses a non-std container and thus we can't rely on ADL to find begin/end etc.
using namespace std;

// Define minimal metaprogramming tools, avoid including anything

#define DEFINE_CONDITIONAL_CALLER_OF_FREE_MEMBER(free_name, member_name) \
template <class T, class = void> \
struct conditional_caller_of_##free_name { \
constexpr void operator()(T&) {} \
}; \
\
template <class T> \
struct conditional_caller_of_##free_name<T&, decltype((void) static_cast<T*>(nullptr)->member_name())> { \
constexpr auto operator()(T& t) { \
return free_name(t); \
} \
};

#define DEFINE_CONDITIONAL_CALLER_OF(name) DEFINE_CONDITIONAL_CALLER_OF_FREE_MEMBER(name, name)

#define CONDITIONALLY_CALL(c, name) conditional_caller_of_##name<decltype(c)>{}(c)

DEFINE_CONDITIONAL_CALLER_OF(rbegin);
DEFINE_CONDITIONAL_CALLER_OF(rend);
DEFINE_CONDITIONAL_CALLER_OF(crbegin);
DEFINE_CONDITIONAL_CALLER_OF(crend);
DEFINE_CONDITIONAL_CALLER_OF(size);
#if _HAS_CXX20
DEFINE_CONDITIONAL_CALLER_OF_FREE_MEMBER(ssize, size); // N5032 [iterator.range]/18
#endif
DEFINE_CONDITIONAL_CALLER_OF(empty);
DEFINE_CONDITIONAL_CALLER_OF(data);

template <class C>
void test_free_container_functions(C& c) {
(void) begin(c);
(void) end(c);
(void) cbegin(c);
(void) cend(c);
CONDITIONALLY_CALL(c, rbegin); // missing e.g. for forward_list
CONDITIONALLY_CALL(c, rend); // missing e.g. for forward_list
CONDITIONALLY_CALL(c, crbegin); // missing e.g. for forward_list
CONDITIONALLY_CALL(c, crend); // missing e.g. for forward_list
CONDITIONALLY_CALL(c, size); // missing e.g. for optional
#if _HAS_CXX20
CONDITIONALLY_CALL(c, ssize); // missing e.g. for optional
#endif
CONDITIONALLY_CALL(c, empty); // missing e.g. for valarray
CONDITIONALLY_CALL(c, data); // missing e.g. for valarray
}

inline void test_free_array_functions() {
int a[]{1, 2, 3};

(void) begin(a);
(void) end(a);
(void) cbegin(a);
(void) cend(a);
(void) rbegin(a);
(void) rend(a);
(void) crbegin(a);
(void) crend(a);
(void) size(a);
#if _HAS_CXX20
(void) ssize(a);
#endif
(void) empty(a);
(void) data(a);
}
} // namespace detail

template <class C>
void shared_test(C& c) {
detail::test_free_container_functions(c);
// as_const from <utility> not required to be available
detail::test_free_container_functions(const_cast<const C&>(c));

detail::test_free_array_functions();
}
48 changes: 48 additions & 0 deletions tests/std/tests/GH_005968_headers_provide_begin_end/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

void test_array();
void test_deque();
void test_flat_map();
void test_flat_set();
void test_forward_list();
void test_hive();
void test_inplace_vector();
void test_iterator();
void test_list();
void test_map();
void test_optional();
void test_regex();
void test_set();
void test_span();
void test_stacktrace();
void test_string();
void test_string_view();
void test_unordered_map();
void test_unordered_set();
void test_valarray();
void test_vector();

int main() {
test_array();
test_deque();
test_flat_map();
test_flat_set();
test_forward_list();
test_hive();
test_inplace_vector();
test_iterator();
test_list();
test_map();
test_optional();
test_regex();
test_set();
test_span();
test_stacktrace();
test_string();
test_string_view();
test_unordered_map();
test_unordered_set();
test_valarray();
test_vector();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <array>

#include "shared_test.hpp"

void test_array() {
std::array<int, 3> container{1, 2, 3};
shared_test(container);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <deque>

#include "shared_test.hpp"

void test_deque() {
std::deque<int> container{1, 2, 3};
shared_test(container);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <version>
#if defined(__cpp_lib_flat_map)
static_assert(false, "When this feature is implemented, update this to a Standard mode check.");

#include <flat_map>

#include "shared_test.hpp"

void test_flat_map() {
{
std::flat_map<int, int> container{
{1, 5},
{3, 7},
};
shared_test(container);
}

{
std::flat_multimap<int, int> container2{
{1, 5},
{3, 7},
};
shared_test(container2);
}
}

#else // ^^^ defined(__cpp_lib_flat_map) / !defined(__cpp_lib_flat_map) vvv

void test_flat_map() {}

#endif // ^^^ !defined(__cpp_lib_flat_map) ^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <version>
#if defined(__cpp_lib_flat_set)
static_assert(false, "When this feature is implemented, update this to a Standard mode check.");

#include <flat_set>

#include "shared_test.hpp"

void test_flat_set() {
{
std::flat_set<int> container{1, 2, 3};
shared_test(container);
}

{
std::flat_multiset<int> container2{1, 2, 3};
shared_test(container2);
}
}

#else // ^^^ defined(__cpp_lib_flat_set) / !defined(__cpp_lib_flat_set) vvv

void test_flat_set() {}

#endif // ^^^ !defined(__cpp_lib_flat_set) ^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <forward_list>

#include "shared_test.hpp"

void test_forward_list() {
std::forward_list<int> container{1, 2, 3};
shared_test(container);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <version>
#if defined(__cpp_lib_hive)
static_assert(false, "When this feature is implemented, update this to a Standard mode check.");

#include <hive>

#include "shared_test.hpp"

void test_hive() {
std::hive<int> container{1, 2, 3};
shared_test(container);
}

#else // ^^^ defined(__cpp_lib_hive) / !defined(__cpp_lib_hive) vvv

void test_hive() {}

#endif // ^^^ !defined(__cpp_lib_hive) ^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <version>
#if defined(__cpp_lib_inplace_vector)
static_assert(false, "When this feature is implemented, update this to a Standard mode check.");

#include <inplace_vector>

#include "shared_test.hpp"

void test_inplace_vector() {
std::inplace_vector<int, 3> container{1, 2, 3};
shared_test(container);
}

#else // ^^^ defined(__cpp_lib_inplace_vector) / !defined(__cpp_lib_inplace_vector) vvv

void test_inplace_vector() {}

#endif // ^^^ !defined(__cpp_lib_inplace_vector) ^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <iterator>

#include "shared_test.hpp"

struct minimal_container {
static constexpr size_t magic_value = 3376942;

constexpr void begin() const {}
constexpr void end() const {}
constexpr void cbegin() const {}
constexpr void cend() const {}
constexpr void rbegin() const {}
constexpr void rend() const {}
constexpr void crbegin() const {}
constexpr void crend() const {}
constexpr size_t size() const {
return magic_value;
}
constexpr void empty() const {}
constexpr void data() const {}
};


// Self-test the template machinery to check it properly detects member functions
namespace detail {
template <class C>
constexpr bool minimal_container_test(C& c) {
// when the CONDITIONALLY_CALL expression fails to detect the member, it has type void, i.e. clearly
// incompatible with operator==. If the detection mechanism did not work properly, this would fail to compile.
return CONDITIONALLY_CALL(c, size) == minimal_container::magic_value;
}

constexpr minimal_container min_cont;
static_assert(minimal_container_test(min_cont), "The member detection utility is broken");
} // namespace detail

void test_iterator() {
minimal_container container;

shared_test(container);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <list>

#include "shared_test.hpp"

void test_list() {
std::list<int> container{1, 2, 3};
shared_test(container);
}
Loading