Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extern "C++" as a temporary workaround for #include/import coexistence #4154

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Add test coverage.
StephanTLavavej committed Nov 8, 2023
commit 13de3c30d6f1f4a74f592154b462e99a93ce4218
Original file line number Diff line number Diff line change
@@ -17,10 +17,12 @@ def getBuildSteps(self, test, litConfig, shared):
testCpp = test.getSourcePath()
sourceDir = os.path.dirname(testCpp)
test2Cpp = os.path.join(sourceDir, 'test2.cpp')
test3Cpp = os.path.join(sourceDir, 'test3.cpp')
test4Cpp = os.path.join(sourceDir, 'test4.cpp')
classicCpp = os.path.join(sourceDir, 'classic.cpp')

# Dependency order is important here:
inputPaths = [stdIxx, stdCompatIxx, testCpp, test2Cpp, classicCpp]
inputPaths = [stdIxx, stdCompatIxx, testCpp, test2Cpp, test3Cpp, test4Cpp, classicCpp]

cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags]

Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ ()
my $stdCompatIxx = "$stlModulesDir\\std.compat.ixx";

# Dependency order is important here:
my @inputPaths = ($stdIxx, $stdCompatIxx, "test.cpp", "test2.cpp", "classic.cpp");
my @inputPaths = ($stdIxx, $stdCompatIxx, "test.cpp", "test2.cpp", "test3.cpp", "test4.cpp", "classic.cpp");

Run::ExecuteCL(join(" ", @inputPaths, "/Fe$cwd.exe"));
}
4 changes: 4 additions & 0 deletions tests/std/tests/P2465R3_standard_library_modules/test.cpp
Original file line number Diff line number Diff line change
@@ -13,12 +13,16 @@ import std;
void prepare_test_environment();
void all_std_cmeow_tests();
void test_module_std_compat();
void test_include_all_then_import_std();
void test_include_all_then_import_std_compat();

int main() {
prepare_test_environment(); // defined in classic.cpp
all_cpp_header_tests(); // defined in test_header_units_and_modules.hpp
all_std_cmeow_tests(); // defined below
test_module_std_compat(); // defined in test2.cpp
test_include_all_then_import_std(); // defined in test3.cpp
test_include_all_then_import_std_compat(); // defined in test4.cpp
}

void test_std_cassert() {
30 changes: 30 additions & 0 deletions tests/std/tests/P2465R3_standard_library_modules/test3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifdef _MSVC_INTERNAL_TESTING // TRANSITION, VS 2022 17.9 Preview 3
#include <__msvc_all_public_headers.hpp>
#else // ^^^ no workaround / workaround vvv
#include <assert.h> // intentionally not <cassert>
#endif // ^^^ workaround ^^^

import std;

// INTENTIONALLY AVOIDED: using namespace std;

void test_include_all_then_import_std() {
// Verify that std::vector and std::ranges algorithms are available:
std::vector<int> v{31, 41, 59, 26, 53, 58, 97, 93};
assert(!std::ranges::is_sorted(v));
std::ranges::sort(v);
assert(std::ranges::is_sorted(v));
const std::vector<int> sorted{26, 31, 41, 53, 58, 59, 93, 97};
assert(v == sorted);

// Verify that the Sufficient Additional Overloads are available for std::sqrt():
assert(std::sqrt(25.0) == 5.0);
assert(std::sqrt(25.0f) == 5.0f);
assert(std::sqrt(25) == 5.0);
static_assert(std::is_same_v<decltype(std::sqrt(25.0)), double>);
static_assert(std::is_same_v<decltype(std::sqrt(25.0f)), float>);
static_assert(std::is_same_v<decltype(std::sqrt(25)), double>);
}
38 changes: 38 additions & 0 deletions tests/std/tests/P2465R3_standard_library_modules/test4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifdef _MSVC_INTERNAL_TESTING // TRANSITION, VS 2022 17.9 Preview 3
#include <__msvc_all_public_headers.hpp>
#else // ^^^ no workaround / workaround vvv
#include <assert.h> // intentionally not <cassert>
#endif // ^^^ workaround ^^^

import std.compat;

// INTENTIONALLY AVOIDED: using namespace std;

void test_include_all_then_import_std_compat() {
// Verify that std::vector and std::ranges algorithms are available:
std::vector<int> v{31, 41, 59, 26, 53, 58, 97, 93};
assert(!std::ranges::is_sorted(v));
std::ranges::sort(v);
assert(std::ranges::is_sorted(v));
const std::vector<int> sorted{26, 31, 41, 53, 58, 59, 93, 97};
assert(v == sorted);

// Verify that the Sufficient Additional Overloads are available for std::sqrt():
assert(std::sqrt(25.0) == 5.0);
assert(std::sqrt(25.0f) == 5.0f);
assert(std::sqrt(25) == 5.0);
static_assert(std::is_same_v<decltype(std::sqrt(25.0)), double>);
static_assert(std::is_same_v<decltype(std::sqrt(25.0f)), float>);
static_assert(std::is_same_v<decltype(std::sqrt(25)), double>);

// Verify that the Sufficient Additional Overloads are available for ::sqrt():
assert(::sqrt(25.0) == 5.0);
assert(::sqrt(25.0f) == 5.0f);
assert(::sqrt(25) == 5.0);
static_assert(std::is_same_v<decltype(::sqrt(25.0)), double>);
static_assert(std::is_same_v<decltype(::sqrt(25.0f)), float>);
static_assert(std::is_same_v<decltype(::sqrt(25)), double>);
}