Skip to content

Commit 98c6f5d

Browse files
committed
Use braced initialization
I didn't apply braced initialization to very common C programming patterns in the unittest because when something is extremely common, I think it increases cognitive load when reading. For example int fd = open(...); vs int fd{open(...)}; I did change all uses in the runtime implementation as requested in code review.
1 parent dcf7419 commit 98c6f5d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

flang/runtime/extensions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ void RTNAME(Sleep)(std::int64_t seconds) {
143143
#ifndef _WIN32
144144
std::int64_t FORTRAN_PROCEDURE_NAME(access)(const char *name,
145145
std::int64_t nameLength, const char *mode, std::int64_t modeLength) {
146-
std::int64_t ret = -1;
146+
std::int64_t ret{-1};
147147
if (nameLength <= 0 || modeLength <= 0 || !name || !mode) {
148148
return ret;
149149
}
150150

151151
// ensure name is null terminated
152-
char *newName = nullptr;
152+
char *newName{nullptr};
153153
if (name[nameLength - 1] != '\0') {
154154
newName = static_cast<char *>(std::malloc(nameLength + 1));
155155
std::memcpy(newName, name, nameLength);
@@ -158,11 +158,11 @@ std::int64_t FORTRAN_PROCEDURE_NAME(access)(const char *name,
158158
}
159159

160160
// calculate mode
161-
bool read = false;
162-
bool write = false;
163-
bool execute = false;
164-
bool exists = false;
165-
int imode = 0;
161+
bool read{false};
162+
bool write{false};
163+
bool execute{false};
164+
bool exists{false};
165+
int imode{0};
166166

167167
for (std::int64_t i = 0; i < modeLength; ++i) {
168168
switch (mode[i]) {

flang/unittests/Runtime/AccessTest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ namespace {
2424
struct AccessTests : public CrashHandlerFixture {};
2525

2626
struct AccessType {
27-
bool read = false;
28-
bool write = false;
29-
bool execute = false;
30-
bool exists = false;
27+
bool read{false};
28+
bool write{false};
29+
bool execute{false};
30+
bool exists{false};
3131
};
3232

3333
} // namespace
@@ -44,15 +44,15 @@ static std::string addPIDSuffix(const char *name) {
4444

4545
static std::filesystem::path createTemporaryFile(
4646
const char *name, const AccessType &accessType) {
47-
std::filesystem::path path =
48-
std::filesystem::temp_directory_path() / addPIDSuffix(name);
47+
std::filesystem::path path{
48+
std::filesystem::temp_directory_path() / addPIDSuffix(name)};
4949

5050
// O_CREAT | O_EXCL enforces that this file is newly created by this call.
5151
// This feels risky. If we don't have permission to create files in the
5252
// temporary directory or if the files already exist, the test will fail.
5353
// But we can't use std::tmpfile() because we need a path to the file and
5454
// to control the filesystem permissions
55-
mode_t mode = 0;
55+
mode_t mode{0};
5656
if (accessType.read) {
5757
mode |= S_IRUSR;
5858
}
@@ -75,7 +75,7 @@ static std::filesystem::path createTemporaryFile(
7575

7676
static std::int64_t callAccess(
7777
const std::filesystem::path &path, const AccessType &accessType) {
78-
const char *cpath = path.c_str();
78+
const char *cpath{path.c_str()};
7979
std::int64_t pathlen = std::strlen(cpath);
8080

8181
std::string mode;

0 commit comments

Comments
 (0)