Skip to content

Commit

Permalink
(Hopefully) Fix Obj-C++ compilation of matchers
Browse files Browse the repository at this point in the history
Thanks to bdb for the patch, related to #1661
  • Loading branch information
horenmar committed Aug 7, 2019
1 parent 7a6af7b commit 0ab11aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions include/internal/catch_matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ namespace Matchers {
virtual bool match( ObjectT const& arg ) const = 0;
};

#if defined(__OBJC__)
// Hack to fix Catch GH issue #1661. Could use id for generic Object support.
// use of const for Object pointers is very uncommon and under ARC it causes some kind of signature mismatch that breaks compilation
template<>
struct MatcherMethod<NSString*> {
virtual bool match( NSString* arg ) const = 0;
};
#endif

#ifdef __clang__
# pragma clang diagnostic pop
#endif
Expand Down
10 changes: 5 additions & 5 deletions include/internal/catch_objc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace Catch {
arcSafeRelease( m_substr );
}

bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return false;
}

Expand All @@ -126,7 +126,7 @@ namespace Catch {
struct Equals : StringHolder {
Equals( NSString* substr ) : StringHolder( substr ){}

bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return (str != nil || m_substr == nil ) &&
[str isEqualToString:m_substr];
}
Expand All @@ -139,7 +139,7 @@ namespace Catch {
struct Contains : StringHolder {
Contains( NSString* substr ) : StringHolder( substr ){}

bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location != NSNotFound;
}
Expand All @@ -152,7 +152,7 @@ namespace Catch {
struct StartsWith : StringHolder {
StartsWith( NSString* substr ) : StringHolder( substr ){}

bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location == 0;
}
Expand All @@ -164,7 +164,7 @@ namespace Catch {
struct EndsWith : StringHolder {
EndsWith( NSString* substr ) : StringHolder( substr ){}

bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location == [str length] - [m_substr length];
}
Expand Down

0 comments on commit 0ab11aa

Please sign in to comment.