Add deep const to unique_ptr::operator->

This commit is contained in:
Martin Hořeňovský 2021-05-19 11:00:53 +02:00
parent 9137e591fa
commit 023b5306b4
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 25 additions and 21 deletions

View File

@ -64,7 +64,11 @@ namespace Detail {
assert(m_ptr); assert(m_ptr);
return *m_ptr; return *m_ptr;
} }
T* operator->() const noexcept { T* operator->() noexcept {
assert(m_ptr);
return m_ptr;
}
T const* operator->() const noexcept {
assert(m_ptr); assert(m_ptr);
return m_ptr; return m_ptr;
} }

View File

@ -22,54 +22,54 @@ namespace Catch {
} }
void ListeningReporter::noMatchingTestCases( std::string const& spec ) { void ListeningReporter::noMatchingTestCases( std::string const& spec ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->noMatchingTestCases( spec ); listener->noMatchingTestCases( spec );
} }
m_reporter->noMatchingTestCases( spec ); m_reporter->noMatchingTestCases( spec );
} }
void ListeningReporter::reportInvalidArguments(std::string const&arg){ void ListeningReporter::reportInvalidArguments(std::string const&arg){
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->reportInvalidArguments( arg ); listener->reportInvalidArguments( arg );
} }
m_reporter->reportInvalidArguments( arg ); m_reporter->reportInvalidArguments( arg );
} }
void ListeningReporter::benchmarkPreparing( std::string const& name ) { void ListeningReporter::benchmarkPreparing( std::string const& name ) {
for (auto const& listener : m_listeners) { for (auto& listener : m_listeners) {
listener->benchmarkPreparing(name); listener->benchmarkPreparing(name);
} }
m_reporter->benchmarkPreparing(name); m_reporter->benchmarkPreparing(name);
} }
void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) { void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->benchmarkStarting( benchmarkInfo ); listener->benchmarkStarting( benchmarkInfo );
} }
m_reporter->benchmarkStarting( benchmarkInfo ); m_reporter->benchmarkStarting( benchmarkInfo );
} }
void ListeningReporter::benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) { void ListeningReporter::benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->benchmarkEnded( benchmarkStats ); listener->benchmarkEnded( benchmarkStats );
} }
m_reporter->benchmarkEnded( benchmarkStats ); m_reporter->benchmarkEnded( benchmarkStats );
} }
void ListeningReporter::benchmarkFailed( std::string const& error ) { void ListeningReporter::benchmarkFailed( std::string const& error ) {
for (auto const& listener : m_listeners) { for (auto& listener : m_listeners) {
listener->benchmarkFailed(error); listener->benchmarkFailed(error);
} }
m_reporter->benchmarkFailed(error); m_reporter->benchmarkFailed(error);
} }
void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) { void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->testRunStarting( testRunInfo ); listener->testRunStarting( testRunInfo );
} }
m_reporter->testRunStarting( testRunInfo ); m_reporter->testRunStarting( testRunInfo );
} }
void ListeningReporter::testGroupStarting( GroupInfo const& groupInfo ) { void ListeningReporter::testGroupStarting( GroupInfo const& groupInfo ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->testGroupStarting( groupInfo ); listener->testGroupStarting( groupInfo );
} }
m_reporter->testGroupStarting( groupInfo ); m_reporter->testGroupStarting( groupInfo );
@ -77,21 +77,21 @@ namespace Catch {
void ListeningReporter::testCaseStarting( TestCaseInfo const& testInfo ) { void ListeningReporter::testCaseStarting( TestCaseInfo const& testInfo ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->testCaseStarting( testInfo ); listener->testCaseStarting( testInfo );
} }
m_reporter->testCaseStarting( testInfo ); m_reporter->testCaseStarting( testInfo );
} }
void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) { void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->sectionStarting( sectionInfo ); listener->sectionStarting( sectionInfo );
} }
m_reporter->sectionStarting( sectionInfo ); m_reporter->sectionStarting( sectionInfo );
} }
void ListeningReporter::assertionStarting( AssertionInfo const& assertionInfo ) { void ListeningReporter::assertionStarting( AssertionInfo const& assertionInfo ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->assertionStarting( assertionInfo ); listener->assertionStarting( assertionInfo );
} }
m_reporter->assertionStarting( assertionInfo ); m_reporter->assertionStarting( assertionInfo );
@ -99,35 +99,35 @@ namespace Catch {
// The return value indicates if the messages buffer should be cleared: // The return value indicates if the messages buffer should be cleared:
bool ListeningReporter::assertionEnded( AssertionStats const& assertionStats ) { bool ListeningReporter::assertionEnded( AssertionStats const& assertionStats ) {
for( auto const& listener : m_listeners ) { for( auto& listener : m_listeners ) {
static_cast<void>( listener->assertionEnded( assertionStats ) ); static_cast<void>( listener->assertionEnded( assertionStats ) );
} }
return m_reporter->assertionEnded( assertionStats ); return m_reporter->assertionEnded( assertionStats );
} }
void ListeningReporter::sectionEnded( SectionStats const& sectionStats ) { void ListeningReporter::sectionEnded( SectionStats const& sectionStats ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->sectionEnded( sectionStats ); listener->sectionEnded( sectionStats );
} }
m_reporter->sectionEnded( sectionStats ); m_reporter->sectionEnded( sectionStats );
} }
void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->testCaseEnded( testCaseStats ); listener->testCaseEnded( testCaseStats );
} }
m_reporter->testCaseEnded( testCaseStats ); m_reporter->testCaseEnded( testCaseStats );
} }
void ListeningReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { void ListeningReporter::testGroupEnded( TestGroupStats const& testGroupStats ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->testGroupEnded( testGroupStats ); listener->testGroupEnded( testGroupStats );
} }
m_reporter->testGroupEnded( testGroupStats ); m_reporter->testGroupEnded( testGroupStats );
} }
void ListeningReporter::testRunEnded( TestRunStats const& testRunStats ) { void ListeningReporter::testRunEnded( TestRunStats const& testRunStats ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->testRunEnded( testRunStats ); listener->testRunEnded( testRunStats );
} }
m_reporter->testRunEnded( testRunStats ); m_reporter->testRunEnded( testRunStats );
@ -135,28 +135,28 @@ namespace Catch {
void ListeningReporter::skipTest( TestCaseInfo const& testInfo ) { void ListeningReporter::skipTest( TestCaseInfo const& testInfo ) {
for ( auto const& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->skipTest( testInfo ); listener->skipTest( testInfo );
} }
m_reporter->skipTest( testInfo ); m_reporter->skipTest( testInfo );
} }
void ListeningReporter::listReporters(std::vector<ReporterDescription> const& descriptions) { void ListeningReporter::listReporters(std::vector<ReporterDescription> const& descriptions) {
for (auto const& listener : m_listeners) { for (auto& listener : m_listeners) {
listener->listReporters(descriptions); listener->listReporters(descriptions);
} }
m_reporter->listReporters(descriptions); m_reporter->listReporters(descriptions);
} }
void ListeningReporter::listTests(std::vector<TestCaseHandle> const& tests) { void ListeningReporter::listTests(std::vector<TestCaseHandle> const& tests) {
for (auto const& listener : m_listeners) { for (auto& listener : m_listeners) {
listener->listTests(tests); listener->listTests(tests);
} }
m_reporter->listTests(tests); m_reporter->listTests(tests);
} }
void ListeningReporter::listTags(std::vector<TagInfo> const& tags) { void ListeningReporter::listTags(std::vector<TagInfo> const& tags) {
for (auto const& listener : m_listeners) { for (auto& listener : m_listeners) {
listener->listTags(tags); listener->listTags(tags);
} }
m_reporter->listTags(tags); m_reporter->listTags(tags);