Skip to content

Commit ea36eeb

Browse files
committed
enabled and fixed bugprone-narrowing-conversions clang-tidy warnings
1 parent 10f5052 commit ea36eeb

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Checks: >
2020
-boost-use-ranges,
2121
-bugprone-branch-clone,
2222
-bugprone-easily-swappable-parameters,
23-
-bugprone-narrowing-conversions,
2423
-bugprone-switch-missing-default-case,
2524
-concurrency-mt-unsafe,
2625
-misc-no-recursion,

simplecpp.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,8 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
765765
if (ppTok->next && (ppTok->next->str() == "error" || ppTok->next->str() == "warning")) {
766766
char prev = ' ';
767767
while (stream.good() && (prev == '\\' || (ch != '\r' && ch != '\n'))) {
768-
currentToken += ch;
769-
prev = ch;
768+
currentToken += static_cast<char>(ch);
769+
prev = static_cast<char>(ch);
770770
ch = stream.readChar();
771771
}
772772
stream.ungetChar();
@@ -780,7 +780,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
780780
if (isNameChar(ch)) {
781781
const bool num = !!std::isdigit(ch);
782782
while (stream.good() && isNameChar(ch)) {
783-
currentToken += ch;
783+
currentToken += static_cast<char>(ch);
784784
ch = stream.readChar();
785785
if (num && ch=='\'' && isNameChar(stream.peekChar()))
786786
ch = stream.readChar();
@@ -792,14 +792,14 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
792792
// comment
793793
else if (ch == '/' && stream.peekChar() == '/') {
794794
while (stream.good() && ch != '\n') {
795-
currentToken += ch;
795+
currentToken += static_cast<char>(ch);
796796
ch = stream.readChar();
797797
if (ch == '\\') {
798798
TokenString tmp;
799-
char tmp_ch = ch;
799+
char tmp_ch = static_cast<char>(ch);
800800
while ((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
801801
tmp += tmp_ch;
802-
tmp_ch = stream.readChar();
802+
tmp_ch = static_cast<char>(stream.readChar());
803803
}
804804
if (!stream.good()) {
805805
break;
@@ -813,7 +813,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
813813
if (pos < check_portability.size() - 1U && check_portability[pos] == '\\')
814814
portabilityBackslash(outputList, location);
815815
++multiline;
816-
tmp_ch = stream.readChar();
816+
tmp_ch = static_cast<char>(stream.readChar());
817817
currentToken += '\n';
818818
}
819819
ch = tmp_ch;
@@ -830,7 +830,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
830830
(void)stream.readChar();
831831
ch = stream.readChar();
832832
while (stream.good()) {
833-
currentToken += ch;
833+
currentToken += static_cast<char>(ch);
834834
if (currentToken.size() >= 4U && endsWith(currentToken, COMMENT_END))
835835
break;
836836
ch = stream.readChar();
@@ -862,11 +862,11 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
862862
// C++11 raw string literal
863863
if (ch == '\"' && !prefix.empty() && *cback()->str().rbegin() == 'R') {
864864
std::string delim;
865-
currentToken = ch;
865+
currentToken = static_cast<char>(ch);
866866
prefix.resize(prefix.size() - 1);
867867
ch = stream.readChar();
868868
while (stream.good() && ch != '(' && ch != '\n') {
869-
delim += ch;
869+
delim += static_cast<char>(ch);
870870
ch = stream.readChar();
871871
}
872872
if (!stream.good() || ch == '\n') {
@@ -882,7 +882,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
882882
}
883883
const std::string endOfRawString(')' + delim + currentToken);
884884
while (stream.good() && (!endsWith(currentToken, endOfRawString) || currentToken.size() <= 1))
885-
currentToken += stream.readChar();
885+
currentToken += static_cast<char>(stream.readChar());
886886
if (!endsWith(currentToken, endOfRawString)) {
887887
if (outputList) {
888888
Output err = {
@@ -907,7 +907,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
907907
continue;
908908
}
909909

910-
currentToken = readUntil(stream,location,ch,ch,outputList);
910+
currentToken = readUntil(stream,location,static_cast<char>(ch),static_cast<char>(ch),outputList);
911911
if (currentToken.size() < 2U)
912912
// Error is reported by readUntil()
913913
return;
@@ -939,7 +939,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
939939
}
940940

941941
else {
942-
currentToken += ch;
942+
currentToken += static_cast<char>(ch);
943943
}
944944

945945
if (*currentToken.begin() == '<') {
@@ -1001,7 +1001,7 @@ static bool isFloatSuffix(const simplecpp::Token *tok)
10011001
{
10021002
if (!tok || tok->str().size() != 1U)
10031003
return false;
1004-
const char c = std::tolower(tok->str()[0]);
1004+
const char c = static_cast<char>(std::tolower(tok->str()[0]));
10051005
return c == 'f' || c == 'l';
10061006
}
10071007

@@ -1400,7 +1400,7 @@ std::string simplecpp::TokenList::readUntil(Stream &stream, const Location &loca
14001400
bool backslash = false;
14011401
char ch = 0;
14021402
while (ch != end && ch != '\r' && ch != '\n' && stream.good()) {
1403-
ch = stream.readChar();
1403+
ch = static_cast<char>(stream.readChar());
14041404
if (backslash && ch == '\n') {
14051405
ch = 0;
14061406
backslash = false;
@@ -1412,7 +1412,7 @@ std::string simplecpp::TokenList::readUntil(Stream &stream, const Location &loca
14121412
bool update_ch = false;
14131413
char next = 0;
14141414
do {
1415-
next = stream.readChar();
1415+
next = static_cast<char>(stream.readChar());
14161416
if (next == '\r' || next == '\n') {
14171417
ret.erase(ret.size()-1U);
14181418
backslash = (next == '\r');
@@ -2842,7 +2842,7 @@ long long simplecpp::characterLiteralToLL(const std::string& str)
28422842
case 'U': {
28432843
// universal character names have exactly 4 or 8 digits
28442844
const std::size_t ndigits = (escape == 'u' ? 4 : 8);
2845-
value = stringToULLbounded(str, pos, 16, ndigits, ndigits);
2845+
value = stringToULLbounded(str, pos, 16, static_cast<std::ptrdiff_t>(ndigits), ndigits);
28462846

28472847
// UTF-8 encodes code points above 0x7f in multiple code units
28482848
// code points above 0x10ffff are not allowed
@@ -2926,7 +2926,7 @@ long long simplecpp::characterLiteralToLL(const std::string& str)
29262926

29272927
// All other cases are unsigned. Since long long is at least 64bit wide,
29282928
// while the literals at most 32bit wide, the conversion preserves all values.
2929-
return multivalue;
2929+
return static_cast<long long>(multivalue);
29302930
}
29312931

29322932
/**

0 commit comments

Comments
 (0)