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 -Wsign-conversion to the list of common warning flags #2775

Open
wants to merge 11 commits into
base: devel
Choose a base branch
from
1 change: 1 addition & 0 deletions CMake/CatchMiscFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function(add_warnings_to_targets targets)
"-Wreorder"
"-Wreturn-std-move"
"-Wshadow"
"-Wsign-conversion"
"-Wstrict-aliasing"
"-Wsuggest-destructor-override"
"-Wsuggest-override"
Expand Down
32 changes: 16 additions & 16 deletions examples/210-Evt-EventListeners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


namespace {
std::string ws(int const level) {
std::string ws(std::size_t const level) {
return std::string( 2 * level, ' ' );
}

Expand All @@ -45,7 +45,7 @@ std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
// std::size_t line;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::SourceLineInfo const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::SourceLineInfo const& info ) {
os << ws(level ) << title << ":\n"
<< ws(level+1) << "- file: " << info.file << "\n"
<< ws(level+1) << "- line: " << info.line << "\n";
Expand All @@ -59,14 +59,14 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// unsigned int sequence;
//};

void print( std::ostream& os, int const level, Catch::MessageInfo const& info ) {
void print( std::ostream& os, std::size_t const level, Catch::MessageInfo const& info ) {
os << ws(level+1) << "- macroName: '" << info.macroName << "'\n"
<< ws(level+1) << "- message '" << info.message << "'\n";
print( os,level+1 , "- lineInfo", info.lineInfo );
os << ws(level+1) << "- sequence " << info.sequence << "\n";
}

void print( std::ostream& os, int const level, std::string const& title, std::vector<Catch::MessageInfo> const& v ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, std::vector<Catch::MessageInfo> const& v ) {
os << ws(level ) << title << ":\n";
for ( const auto& x : v )
{
Expand All @@ -81,7 +81,7 @@ void print( std::ostream& os, int const level, std::string const& title, std::ve
// std::string name;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::TestRunInfo const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::TestRunInfo const& info ) {
os << ws(level ) << title << ":\n"
<< ws(level+1) << "- name: " << info.name << "\n";
}
Expand All @@ -96,7 +96,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// std::size_t failedButOk = 0;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::Counts const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::Counts const& info ) {
os << ws(level ) << title << ":\n"
<< ws(level+1) << "- total(): " << info.total() << "\n"
<< ws(level+1) << "- allPassed(): " << info.allPassed() << "\n"
Expand All @@ -111,7 +111,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// Counts testCases;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::Totals const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::Totals const& info ) {
os << ws(level) << title << ":\n";
print( os, level+1, "- assertions", info.assertions );
print( os, level+1, "- testCases" , info.testCases );
Expand All @@ -123,7 +123,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// bool aborting;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::TestRunStats const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::TestRunStats const& info ) {
os << ws(level) << title << ":\n";
print( os, level+1 , "- runInfo", info.runInfo );
print( os, level+1 , "- totals" , info.totals );
Expand Down Expand Up @@ -161,7 +161,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// TestCaseProperties properties = TestCaseProperties::None;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseInfo const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::TestCaseInfo const& info ) {
os << ws(level ) << title << ":\n"
<< ws(level+1) << "- isHidden(): " << info.isHidden() << "\n"
<< ws(level+1) << "- throws(): " << info.throws() << "\n"
Expand All @@ -183,7 +183,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// bool aborting;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseStats const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::TestCaseStats const& info ) {
os << ws(level ) << title << ":\n";
print( os, level+1 , "- testInfo", *info.testInfo );
print( os, level+1 , "- totals" , info.totals );
Expand All @@ -198,7 +198,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// SourceLineInfo lineInfo;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::SectionInfo const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::SectionInfo const& info ) {
os << ws(level ) << title << ":\n"
<< ws(level+1) << "- name: " << info.name << "\n";
print( os, level+1 , "- lineInfo", info.lineInfo );
Expand All @@ -211,7 +211,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// bool missingAssertions;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::SectionStats const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::SectionStats const& info ) {
os << ws(level ) << title << ":\n";
print( os, level+1 , "- sectionInfo", info.sectionInfo );
print( os, level+1 , "- assertions" , info.assertions );
Expand All @@ -227,7 +227,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// ResultDisposition::Flags resultDisposition;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::AssertionInfo const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::AssertionInfo const& info ) {
os << ws(level ) << title << ":\n"
<< ws(level+1) << "- macroName: '" << info.macroName << "'\n";
print( os, level+1 , "- lineInfo" , info.lineInfo );
Expand All @@ -245,7 +245,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// ResultWas::OfType resultType;
//};

void print( std::ostream& os, int const level, std::string const& title, Catch::AssertionResultData const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::AssertionResultData const& info ) {
os << ws(level ) << title << ":\n"
<< ws(level+1) << "- reconstructExpression(): '" << info.reconstructExpression() << "'\n"
<< ws(level+1) << "- message: '" << info.message << "'\n"
Expand All @@ -271,7 +271,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// AssertionResultData m_resultData;
//};

void print( std::ostream& os, int const level, std::string const& title, Catch::AssertionResult const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::AssertionResult const& info ) {
os << ws(level ) << title << ":\n"
<< ws(level+1) << "- isOk(): " << info.isOk() << "\n"
<< ws(level+1) << "- succeeded(): " << info.succeeded() << "\n"
Expand All @@ -296,7 +296,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// Totals totals;
// };

void print( std::ostream& os, int const level, std::string const& title, Catch::AssertionStats const& info ) {
void print( std::ostream& os, std::size_t const level, std::string const& title, Catch::AssertionStats const& info ) {
os << ws(level ) << title << ":\n";
print( os, level+1 , "- assertionResult", info.assertionResult );
print( os, level+1 , "- infoMessages", info.infoMessages );
Expand Down
3 changes: 2 additions & 1 deletion src/catch2/catch_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace Catch {

namespace {
static auto getCurrentNanosecondsSinceEpoch() -> uint64_t {
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count());
}
} // end unnamed namespace

Expand Down
6 changes: 3 additions & 3 deletions src/catch2/internal/catch_test_case_info_hasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ namespace Catch {
const hash_t prime = 1099511628211u;
hash_t hash = 14695981039346656037u;
for ( const char c : t.name ) {
hash ^= c;
hash ^= static_cast<hash_t>(c);
hash *= prime;
}
for ( const char c : t.className ) {
hash ^= c;
hash ^= static_cast<hash_t>(c);
hash *= prime;
}
for ( const Tag& tag : t.tags ) {
for ( const char c : tag.original ) {
hash ^= c;
hash ^= static_cast<hash_t>(c);
hash *= prime;
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/catch2/reporters/catch_reporter_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
std::ostream& m_os;
std::vector<ColumnInfo> m_columnInfos;
ReusableStringStream m_oss;
int m_currentColumn = -1;
std::size_t m_currentColumn = 0;
bool m_isOpen = false;

public:
Expand Down Expand Up @@ -345,11 +345,10 @@
const auto strSize = colStr.size();
tp.m_oss.str("");
tp.open();
if (tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size() - 1)) {
tp.m_currentColumn = -1;
if (tp.m_currentColumn == tp.m_columnInfos.size()) {
tp.m_currentColumn = 0;

Check warning on line 349 in src/catch2/reporters/catch_reporter_console.cpp

View check run for this annotation

Codecov / codecov/patch

src/catch2/reporters/catch_reporter_console.cpp#L349

Added line #L349 was not covered by tests
tp.m_os << '\n';
}
tp.m_currentColumn++;

auto colInfo = tp.m_columnInfos[tp.m_currentColumn];
auto padding = (strSize + 1 < colInfo.width)
Expand All @@ -365,7 +364,7 @@
friend TablePrinter& operator<< (TablePrinter& tp, RowBreak) {
if (tp.m_currentColumn > 0) {
tp.m_os << '\n';
tp.m_currentColumn = -1;
tp.m_currentColumn = 0;

Check warning on line 367 in src/catch2/reporters/catch_reporter_console.cpp

View check run for this annotation

Codecov / codecov/patch

src/catch2/reporters/catch_reporter_console.cpp#L367

Added line #L367 was not covered by tests
}
return tp;
}
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/reporters/catch_reporter_multi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Catch {

// Keep track of how many listeners we have already inserted,
// so that we can insert them into the main vector at the right place
size_t m_insertedListeners = 0;
std::vector<IEventListenerPtr>::difference_type m_insertedListeners = 0;

void updatePreferences(IEventListener const& reporterish);

Expand Down
20 changes: 10 additions & 10 deletions tests/SelfTest/Baselines/compact.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ MatchersRanges.tests.cpp:<line number>: passed: c, !Contains(1) for: { 4, 5, 6 }
MatchersRanges.tests.cpp:<line number>: passed: a, Contains(0, close_enough) for: { 1, 2, 3 } contains element 0
MatchersRanges.tests.cpp:<line number>: passed: b, Contains(0, close_enough) for: { 0, 1, 2 } contains element 0
MatchersRanges.tests.cpp:<line number>: passed: c, !Contains(0, close_enough) for: { 4, 5, 6 } not contains element 0
MatchersRanges.tests.cpp:<line number>: passed: a, Contains(4, [](auto&& lhs, size_t sz) { return lhs.size() == sz; }) for: { "abc", "abcd", "abcde" } contains element 4
MatchersRanges.tests.cpp:<line number>: passed: a, Contains(4u, [](auto&& lhs, size_t sz) { return lhs.size() == sz; }) for: { "abc", "abcd", "abcde" } contains element 4
MatchersRanges.tests.cpp:<line number>: passed: in, Contains(1) for: { 1, 2, 3, 4, 5 } contains element 1
MatchersRanges.tests.cpp:<line number>: passed: in, !Contains(8) for: { 1, 2, 3, 4, 5 } not contains element 8
MatchersRanges.tests.cpp:<line number>: passed: in, Contains(MoveOnlyTestElement{ 2 }) for: { 1, 2, 3 } contains element 2
Expand Down Expand Up @@ -704,21 +704,21 @@ Generators.tests.cpp:<line number>: passed: chunk(2, value(1)), Catch::Generator
Generators.tests.cpp:<line number>: passed: j < i for: -3 < 1
Generators.tests.cpp:<line number>: passed: j < i for: -2 < 1
Generators.tests.cpp:<line number>: passed: j < i for: -1 < 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 4 > 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 4 > 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 4 > 3
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 4 > 1
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 4 > 2
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 4 > 3
Generators.tests.cpp:<line number>: passed: j < i for: -3 < 2
Generators.tests.cpp:<line number>: passed: j < i for: -2 < 2
Generators.tests.cpp:<line number>: passed: j < i for: -1 < 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 8 > 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 8 > 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 8 > 3
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 8 > 1
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 8 > 2
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 8 > 3
Generators.tests.cpp:<line number>: passed: j < i for: -3 < 3
Generators.tests.cpp:<line number>: passed: j < i for: -2 < 3
Generators.tests.cpp:<line number>: passed: j < i for: -1 < 3
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 3
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 12 > 1
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 12 > 2
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 12 > 3
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 123 for: 123 == 123
GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1
Expand Down
20 changes: 10 additions & 10 deletions tests/SelfTest/Baselines/compact.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ MatchersRanges.tests.cpp:<line number>: passed: c, !Contains(1) for: { 4, 5, 6 }
MatchersRanges.tests.cpp:<line number>: passed: a, Contains(0, close_enough) for: { 1, 2, 3 } contains element 0
MatchersRanges.tests.cpp:<line number>: passed: b, Contains(0, close_enough) for: { 0, 1, 2 } contains element 0
MatchersRanges.tests.cpp:<line number>: passed: c, !Contains(0, close_enough) for: { 4, 5, 6 } not contains element 0
MatchersRanges.tests.cpp:<line number>: passed: a, Contains(4, [](auto&& lhs, size_t sz) { return lhs.size() == sz; }) for: { "abc", "abcd", "abcde" } contains element 4
MatchersRanges.tests.cpp:<line number>: passed: a, Contains(4u, [](auto&& lhs, size_t sz) { return lhs.size() == sz; }) for: { "abc", "abcd", "abcde" } contains element 4
MatchersRanges.tests.cpp:<line number>: passed: in, Contains(1) for: { 1, 2, 3, 4, 5 } contains element 1
MatchersRanges.tests.cpp:<line number>: passed: in, !Contains(8) for: { 1, 2, 3, 4, 5 } not contains element 8
MatchersRanges.tests.cpp:<line number>: passed: in, Contains(MoveOnlyTestElement{ 2 }) for: { 1, 2, 3 } contains element 2
Expand Down Expand Up @@ -702,21 +702,21 @@ Generators.tests.cpp:<line number>: passed: chunk(2, value(1)), Catch::Generator
Generators.tests.cpp:<line number>: passed: j < i for: -3 < 1
Generators.tests.cpp:<line number>: passed: j < i for: -2 < 1
Generators.tests.cpp:<line number>: passed: j < i for: -1 < 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 4 > 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 4 > 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 4 > 3
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 4 > 1
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 4 > 2
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 4 > 3
Generators.tests.cpp:<line number>: passed: j < i for: -3 < 2
Generators.tests.cpp:<line number>: passed: j < i for: -2 < 2
Generators.tests.cpp:<line number>: passed: j < i for: -1 < 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 8 > 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 8 > 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 8 > 3
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 8 > 1
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 8 > 2
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 8 > 3
Generators.tests.cpp:<line number>: passed: j < i for: -3 < 3
Generators.tests.cpp:<line number>: passed: j < i for: -2 < 3
Generators.tests.cpp:<line number>: passed: j < i for: -1 < 3
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 3
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 12 > 1
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 12 > 2
Generators.tests.cpp:<line number>: passed: 4u * static_cast<std::size_t>(i) > str.size() for: 12 > 3
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 123 for: 123 == 123
GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1
Expand Down
Loading