Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# we are not interested in these
add_compile_options(-Wno-multichar -Wno-four-char-constants)
# TODO: fix these?
add_compile_options(-Wno-padded -Wno-sign-conversion -Wno-implicit-int-conversion -Wno-shorten-64-to-32 -Wno-shadow-field-in-constructor)
add_compile_options(-Wno-padded -Wno-sign-conversion -Wno-shadow-field-in-constructor)

if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
# TODO: verify this regression still exists in clang-15
Expand Down
14 changes: 7 additions & 7 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ static unsigned short getAndSkipBOM(std::istream &istr)

// The UTF-16 BOM is 0xfffe or 0xfeff.
if (ch1 >= 0xfe) {
const unsigned short bom = (static_cast<unsigned char>(istr.get()) << 8);
const unsigned short bom = static_cast<unsigned short>((static_cast<unsigned char>(istr.get()) << 8));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see that this change improves the readability or makes the code more robust.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes the implicit conversions explicit so you know what actually happens. If possible the code should be changed to avoid these. Since those might not be straight-forward I did not attempt this yet.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't agree. The code is longer and I don't see that it makes the code easier. On the contrary..

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code is shorter and 100% safe. I consider it a false positive from the compiler to warn about this. There can be no loss of precision.

if (istr.peek() >= 0xfe)
return bom | static_cast<unsigned char>(istr.get());
istr.unget();
Expand Down Expand Up @@ -540,7 +540,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
const Token *numtok = cback();
while (numtok->comment)
numtok = numtok->previous;
lineDirective(location.fileIndex, std::atol(numtok->str().c_str()), &location);
lineDirective(location.fileIndex, static_cast<unsigned int>(std::atol(numtok->str().c_str())), &location);
} else if (lastline == "# %num% %str%" || lastline == "# line %num% %str%") {
const Token *strtok = cback();
while (strtok->comment)
Expand All @@ -549,7 +549,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
while (numtok->comment)
numtok = numtok->previous;
lineDirective(fileIndex(replaceAll(strtok->str().substr(1U, strtok->str().size() - 2U),"\\\\","\\")),
std::atol(numtok->str().c_str()), &location);
static_cast<unsigned int>(std::atol(numtok->str().c_str())), &location);
}
// #endfile
else if (lastline == "# endfile" && !loc.empty()) {
Expand Down Expand Up @@ -779,7 +779,7 @@ static bool isFloatSuffix(const simplecpp::Token *tok)
{
if (!tok || tok->str().size() != 1U)
return false;
const char c = std::tolower(tok->str()[0]);
const char c = static_cast<char>(std::tolower(tok->str()[0]));
return c == 'f' || c == 'l';
}

Expand Down Expand Up @@ -1265,7 +1265,7 @@ unsigned int simplecpp::TokenList::fileIndex(const std::string &filename)
return i;
}
files.push_back(filename);
return files.size() - 1U;
return static_cast<unsigned int>(files.size() - 1U);
}


Expand Down Expand Up @@ -2100,11 +2100,11 @@ namespace simplecpp {
const unsigned char driveLetter = cygwinPath[10];
if (std::isalpha(driveLetter)) {
if (cygwinPath.size() == 11) {
windowsPath = toupper(driveLetter);
windowsPath = static_cast<char>(toupper(driveLetter));
windowsPath += ":\\"; // volume root directory
pos = 11;
} else if (cygwinPath[11] == '/') {
windowsPath = toupper(driveLetter);
windowsPath = static_cast<char>(toupper(driveLetter));
windowsPath += ":";
pos = 11;
}
Expand Down
2 changes: 1 addition & 1 deletion test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int assertEquals(const std::string &expected, const std::string &actual,
return (expected == actual);
}

static int assertEquals(const unsigned int &expected, const unsigned int &actual, int line)
static int assertEquals(const unsigned long long &expected, const unsigned long long &actual, int line)
{
return assertEquals(std::to_string(expected), std::to_string(actual), line);
}
Expand Down