Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-01-29 22:03:27 +0100
committerMartin Hořeňovský2017-01-29 22:03:27 +0100
commit60f8ebec49c5bc58d3604bf1a72cd3f7d129bf2e (patch)
treeafed8c06318fc9690d43056142ec27a04124ed99 /include
parent02a69b449f59605cf9fa7f865a3b6daa8d104a79 (diff)
downloadcatch3-60f8ebec49c5bc58d3604bf1a72cd3f7d129bf2e.tar.gz
Use const char* for filename in SourceLineInfo
This is sane, because those `const char*`s are given to us by compiler, from the text area and thus we do not have to manage their lifetimes. We also never want to change them. Also moved copy constructor to compiler-generated methods, not sure why it wasn't -- even before it was the same as a compiler would generate.
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_common.h4
-rw-r--r--include/internal/catch_common.hpp14
2 files changed, 8 insertions, 10 deletions
diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h
index 8d1a86a0..279fffcc 100644
--- a/include/internal/catch_common.h
+++ b/include/internal/catch_common.h
@@ -102,8 +102,8 @@ namespace Catch {
SourceLineInfo();
SourceLineInfo( char const* _file, std::size_t _line );
- SourceLineInfo( SourceLineInfo const& other );
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
+ SourceLineInfo(SourceLineInfo const& other) = default;
SourceLineInfo( SourceLineInfo && ) = default;
SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
SourceLineInfo& operator = ( SourceLineInfo && ) = default;
@@ -112,7 +112,7 @@ namespace Catch {
bool operator == ( SourceLineInfo const& other ) const;
bool operator < ( SourceLineInfo const& other ) const;
- std::string file;
+ char const* file;
std::size_t line;
};
diff --git a/include/internal/catch_common.hpp b/include/internal/catch_common.hpp
index 84fe8e48..3efe85e3 100644
--- a/include/internal/catch_common.hpp
+++ b/include/internal/catch_common.hpp
@@ -10,6 +10,8 @@
#include "catch_common.h"
+#include <cstring>
+
namespace Catch {
bool startsWith( std::string const& s, std::string const& prefix ) {
@@ -75,23 +77,19 @@ namespace Catch {
return os;
}
- SourceLineInfo::SourceLineInfo() : line( 0 ){}
+ SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){}
SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
: file( _file ),
line( _line )
{}
- SourceLineInfo::SourceLineInfo( SourceLineInfo const& other )
- : file( other.file ),
- line( other.line )
- {}
bool SourceLineInfo::empty() const {
- return file.empty();
+ return file[0] == '\0';
}
bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
- return line == other.line && file == other.file;
+ return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
}
bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
- return line < other.line || ( line == other.line && file < other.file );
+ return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
}
void seedRng( IConfig const& config ) {