-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement P2467R1
ios_base::noreplace
: Exclusive Mode For fstream
s (
#3065) Co-authored-by: Casey Carter <[email protected]> Co-authored-by: Stephan T. Lavavej <[email protected]>
- Loading branch information
1 parent
f58deab
commit c550bd0
Showing
7 changed files
with
103 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <cassert> | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <ios> | ||
|
||
namespace fs = std::filesystem; | ||
|
||
const fs::path test_file{L"test.dat"}; | ||
|
||
struct CreateTempFile { | ||
fs::path m_path; | ||
CreateTempFile(const fs::path& path) : m_path(path) { | ||
std::ofstream{path}; | ||
} | ||
|
||
~CreateTempFile() { | ||
fs::remove(m_path); | ||
} | ||
}; | ||
|
||
void test_file_create(const std::ios_base::openmode mode) { | ||
{ | ||
std::fstream file{test_file, mode}; | ||
assert(!file.fail()); | ||
} | ||
assert(fs::exists(test_file)); | ||
fs::remove(test_file); | ||
} | ||
|
||
void test_file_already_exists(const std::ios_base::openmode mode) { | ||
CreateTempFile tmp{test_file}; | ||
std::fstream file{test_file, mode}; | ||
assert(file.fail()); | ||
} | ||
|
||
void test_file_create_fail(const std::ios_base::openmode bad_mode) { | ||
{ | ||
std::fstream file{test_file, bad_mode}; | ||
assert(file.fail()); | ||
} | ||
assert(!fs::exists(test_file)); | ||
} | ||
|
||
int main() { | ||
using IB = std::ios_base; | ||
|
||
test_file_create(IB::out | IB::noreplace); | ||
test_file_create(IB::out | IB::trunc | IB::noreplace); | ||
test_file_create(IB::out | IB::in | IB::trunc | IB::noreplace); | ||
test_file_create(IB::out | IB::binary | IB::noreplace); | ||
test_file_create(IB::out | IB::binary | IB::trunc | IB::noreplace); | ||
test_file_create(IB::out | IB::in | IB::trunc | IB::binary | IB::noreplace); | ||
|
||
test_file_already_exists(IB::out | IB::noreplace); | ||
test_file_already_exists(IB::out | IB::trunc | IB::noreplace); | ||
test_file_already_exists(IB::out | IB::in | IB::trunc | IB::noreplace); | ||
test_file_already_exists(IB::out | IB::binary | IB::noreplace); | ||
test_file_already_exists(IB::out | IB::binary | IB::trunc | IB::noreplace); | ||
test_file_already_exists(IB::out | IB::in | IB::trunc | IB::binary | IB::noreplace); | ||
|
||
test_file_create_fail(IB::in | IB::noreplace); | ||
test_file_create_fail(IB::in | IB::trunc | IB::noreplace); | ||
test_file_create_fail(IB::in | IB::binary | IB::noreplace); | ||
test_file_create_fail(IB::in | IB::binary | IB::trunc | IB::noreplace); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters