catchorg / catchorg/Catch2

[Xcode] Compile failure with ARC enabled in program with an Objective-C++ test runner.

Open
#1,661 7 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

**Describe the bug**

Programs containing Catch2's single_include header fail to compile in Xcode projects that:
- have the target's Build Setting option, `Objective-C Automatic Reference Counting` set to `Yes`; and,
- define CATCH_CONFIG_MAIN in an Objective-C++ `.mm` file.

The following compile time errors are experienced:
```
In file included from /Users/phx/skrach/catch2_arc_compile_bug/catch2arc_compilation_error/catch2arc_compilation_error/main.mm:3:
include/catch2/catch.hpp:4714:58: error: non-virtual member function marked 'override' hides virtual member function
bool match( NSString* const& str ) const override {
^
include/catch2/catch.hpp:3180:26: note: hidden overloaded virtual function 'Catch::Matchers::Impl::MatcherMethod::match' declared here: type mismatch at 1st parameter ('NSString *__strong const &' vs 'NSString *const __autoreleasing &')
virtual bool match( ObjectT const& arg ) const = 0;
^
include/catch2/catch.hpp:4724:58: error: only virtual member functions can be marked 'override'
bool match( NSString* const& str ) const override {
^
include/catch2/catch.hpp:4737:58: error: only virtual member functions can be marked 'override'
bool match( NSString* const& str ) const override {
^
include/catch2/catch.hpp:4750:58: error: only virtual member functions can be marked 'override'
bool match( NSString* const& str ) const override {
^
include/catch2/catch.hpp:4762:58: error: only virtual member functions can be marked 'override'
bool match( NSString* const& str ) const override {
^
include/catch2/catch.hpp:4776:13: error: return type 'Impl::NSStringMatchers::Equals' is an abstract class
Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
^
include/catch2/catch.hpp:3180:26: note: unimplemented pure virtual method 'match' in 'Equals'
virtual bool match( ObjectT const& arg ) const = 0;
^
include/catch2/catch.hpp:4776:48: error: allocating an object of abstract class type 'Impl::NSStringMatchers::Equals'
Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
^
include/catch2/catch.hpp:4779:13: error: return type 'Impl::NSStringMatchers::Contains' is an abstract class
Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
^
include/catch2/catch.hpp:3180:26: note: unimplemented pure virtual method 'match' in 'Contains'
virtual bool match( ObjectT const& arg ) const = 0;
^
include/catch2/catch.hpp:4779:50: error: allocating an object of abstract class type 'Impl::NSStringMatchers::Contains'
Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
^
include/catch2/catch.hpp:4782:13: error: return type 'Impl::NSStringMatchers::StartsWith' is an abstract class
StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
^
include/catch2/catch.hpp:3180:26: note: unimplemented pure virtual method 'match' in 'StartsWith'
virtual bool match( ObjectT const& arg ) const = 0;
^
include/catch2/catch.hpp:4782:52: error: allocating an object of abstract class type 'Impl::NSStringMatchers::StartsWith'
StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
^
include/catch2/catch.hpp:4785:13: error: return type 'Impl::NSStringMatchers::EndsWith' is an abstract class
EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
^
include/catch2/catch.hpp:3180:26: note: unimplemented pure virtual method 'match' in 'EndsWith'
virtual bool match( ObjectT const& arg ) const = 0;
^
include/catch2/catch.hpp:4785:50: error: allocating an object of abstract class type 'Impl::NSStringMatchers::EndsWith'
EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
^
13 errors generated.

```

These errors are resolved when the Build Setting, `Objective-C Automatic Reference Counting` is set to `NO`.

**Expected behavior**
To be able to compile the program.

**Reproduction steps**
Steps to reproduce the bug.

_For iOS_
1. Create a new project from `File->New->Project`. Make sure language selected is Objective-C.
2. Select 'Single View App' from the iOS templates.
3. Go to Build Settings:
- Confirm `Objective-C Automatic Reference Counting` is set to `Yes`.
- Add your catch2 single include header path to `Header Search Paths`.
4. Rename `main.m` to `main.mm`
5. Delete `AppDelegate.*` and `ViewController.*` files.
6. Replace content of `main.mm` with:
```
#define CATCH_CONFIG_MAIN
#include
```
7. Compile the program.

_For macOS_
Follow steps 1-7 from _For iOS_, substituting 2 with:
2. Select 'Cocoa App' from the macOS templates.

**Platform information:**
- OS: **macOS Mojave 10.14.5**
- Compiler+version: **Xcode 10.2.1 (10E1001), Xcode 11.0 beta (11M336w)**
- Catch version: **v2.7.2 -- v2.9.1**

**Additional context**

I have attached a sample project that exhibits this behavior. The sample can be found in the attachment: [catch2arc_compilation_error.zip](https://github.com/catchorg/Catch2/files/3299282/catch2arc_compilation_error.zip).

This sample is packaged with **Catch version v2.9.1**.

After uncompressing the file, open the pre-built Xcode project: `catch2arc_compilation_error.xcodeproj`
In the project, there are two schemes:
- catch2arc_compilation_error
- catch2arc_compilation_success

The targets for each scheme are:
- catch2arc_compilation_error: iOS
- catch2arc_compilation_success: macOS

The Build Setting `Objective-C Automatic Reference Counting` for targets is set to:
- catch2arc_compilation_error: Yes
- catch2arc_compilation_success: No

Compile the scheme `catch2arc_compilation_error` to see the errors.

Contributor guide

Open the contributing guide

Research direction

Open the attached catch2arc_compilation_error.xcodeproj and reproduce the failure from main.mm with Objective-C Automatic Reference Counting enabled. Inspect the reported matcher declarations around include/catch2/catch.hpp lines 3180 and 4714-4785, comparing the ARC-enabled and disabled schemes. Done means the ARC-enabled iOS and macOS project configurations compile successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, objective-c
Domain
build-system, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.