catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.55k stars 3.05k forks source link

catch_amalgamated.cpp(8072,33): error C2593: 'operator <<' is ambiguous #2916

Open pisoir opened 13 hours ago

pisoir commented 13 hours ago

Describe the bug I am using the latest 3.7.1 version of catch_amalgamated.hpp and catch_amalgamated.cpp and I have a simple example file, tests.cpp:

#include "catch_amalgamated.hpp"

unsigned int Factorial(unsigned int number) {
    return number <= 1 ? number : Factorial(number - 1) * number;
}
TEST_CASE("Factorials are computed", "[test]") {
    REQUIRE(Factorial(1) == 1);
    REQUIRE(Factorial(2) == 2);
    REQUIRE(Factorial(3) == 6);
    REQUIRE(Factorial(10) == 3628800);
}

When I try to compile it (in Visual Studio 2019, C++17), I get many of these compilation errors:

catch_amalgamated.cpp(8072,33): error C2593: 'operator <<' is ambiguous
catch_amalgamated.cpp(6598,10): message : could be 'std::ostream &Catch::operator <<(std::ostream &,Catch::StringRef)'
catch_amalgamated.hpp(773,30): message : or       'std::ostream &Catch::operator <<(std::ostream &,Catch::StringRef)' [found using argument-dependent lookup]
catch_amalgamated.cpp(8072,33): message : while trying to match the argument list '(std::basic_ostream<char,std::char_traits<char>>, Catch::StringRef)'
catch_amalgamated.cpp(8106,33): error C2593: 'operator <<' is ambiguous

Any idea why?

Expected behavior The code should compile.

Reproduction steps

  1. Copy catch_amalgamated.hpp and catch_amalgamated.cpp to the solution folder
  2. In the Visual Studio add both files to the project.
  3. Build project -> error

Platform information:

pisoir commented 11 hours ago

It seems that setting the flag /permissive (or /Zc:hiddenFriend-) fixes it. (C/C++ -> Language -> Conformance mode -> No (/permissive)) I would still like to understand what the problem is. Is this a bug in Visual Studio?