approvals / ApprovalTests.cpp

Native ApprovalTests for C++ on Linux, Mac and Windows
https://approvaltestscpp.readthedocs.io/en/latest/
Apache License 2.0
310 stars 50 forks source link

Does not compile with clang13 due to -Werror/-Wdeprecated-copy-with-dtor #194

Closed LtdSauce closed 2 years ago

LtdSauce commented 2 years ago

Hi,

we build our software with Ubuntu Impish (21.10) and the default clang Compiler in that release (clang13). Recently we added ApprovalTests.cpp as a dependency and found out, that it does not compile because of one warning turned into an error. We included it with cmakes FetchContent module.

Steps to reproduce

On Ubuntu Impish run the following:

$ git clone https://github.com/approvals/ApprovalTests.cpp.git
$ cd ApprovalTests.cpp
$ mkdir foo && cd foo
$ CXX=clang++ CC=clang cmake ..
$ make -j4

Produces the following output:

In file included from /tmp/ApprovalTests.cpp/ApprovalTests/writers/ExistingFile.cpp:1:
In file included from /tmp/ApprovalTests.cpp/ApprovalTests/../ApprovalTests/writers/ExistingFile.h:4:
In file included from /tmp/ApprovalTests.cpp/ApprovalTests/../ApprovalTests/core/Options.h:6:
In file included from /tmp/ApprovalTests.cpp/ApprovalTests/../ApprovalTests/namers/DefaultNamerFactory.h:3:
/tmp/ApprovalTests.cpp/ApprovalTests/../ApprovalTests/core/ApprovalNamer.h:10:17: error: definition of implicit copy constructor for 'ApprovalNamer' is deprecated because it has a user-declared destructor [-Werror,-Wdeprecated-copy-with-dtor]
        virtual ~ApprovalNamer() = default;
                ^
/tmp/ApprovalTests.cpp/ApprovalTests/../ApprovalTests/namers/ExistingFileNamer.h:9:11: note: in implicit copy constructor for 'ApprovalTests::ApprovalNamer' first required here
    class ExistingFileNamer : public ApprovalNamer
          ^
/tmp/ApprovalTests.cpp/ApprovalTests/writers/ExistingFile.cpp:58:16: note: in implicit move constructor for 'ApprovalTests::ExistingFileNamer' first required here
        return ExistingFileNamer(filePath, options_);
               ^
1 error generated.
make[2]: *** [ApprovalTests/CMakeFiles/ApprovalTests.dir/build.make:1000: ApprovalTests/CMakeFiles/ApprovalTests.dir/writers/ExistingFile.cpp.o] Fehler 1
make[2]: *** Auf noch nicht beendete Prozesse wird gewartet …
make[1]: *** [CMakeFiles/Makefile2:848: ApprovalTests/CMakeFiles/ApprovalTests.dir/all] Fehler 2
make: *** [Makefile:146: all] Fehler 2

Clang version for the record:

$ clang++ --version
Ubuntu clang version 13.0.0-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Workaround

We were able to build by manually disabling -Wno-error by putting target_compile_options(ApprovalTests PRIVATE -Wno-error) after fetching it.

claremacrae commented 2 years ago

Thanks for reporting this.

We were able to reproduce the problem with this:

https://godbolt.org/z/EGbx1zM3P

And have a proposed fix.

We're hoping to release this on Friday.

LtdSauce commented 2 years ago

Thank you for your fast response and fix!