Repository: catchorg/Catch2
File: projects/SelfTest/UsageTests/Message.tests.cpp (C++)

Code before:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-value" // All the comma operators are side-effect free
#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4709) // comma in indexing operator
#endif

template <typename T1, typename T2>
struct helper_1436 {
    helper_1436(T1 t1_, T2 t2_):
        t1{ t1_ },
        t2{ t2_ }
    {}
    T1 t1;
    T2 t2;
};

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, helper_1436<T1, T2> const& helper) {
    out << "{ " << helper.t1 << ", " << helper.t2 << " }";
    return out;
}

TEST_CASE("CAPTURE can deal with complex expressions involving commas", "[messages][capture]") {
    CAPTURE(std::vector<int>{1, 2, 3}[(0, 1, 2)],
            std::vector<int>{1, 2, 3}[(0, 1)],
            std::vector<int>{1, 2, 3}[0]);
    CAPTURE((helper_1436<int, int>{12, -12}),
            (helper_1436<int, int>(-12, 12)));
    CAPTURE( (1, 2), (2, 3) );
    SUCCEED();
}

TEST_CASE("CAPTURE parses string and character constants", "[messages][capture]") {
    CAPTURE(("comma, in string", "escaped, \", "), "single quote in string,',", "some escapes, \\,\\\\");
    CAPTURE("some, ), unmatched, } prenheses {[<");
    CAPTURE('"', '\'', ',', '}', ')', '(', '{');
    SUCCEED();
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif


Review comment (suggestion):
This should be instead handled by a localized warning suppression instead. The point of the test is to check that `CAPTURE` handles various weird expressions properly, including commas directly in subscript operator.

Code after:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-value" // All the comma operators are side-effect free
#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4709) // comma in indexing operator
#endif

template <typename T1, typename T2>
struct helper_1436 {
    helper_1436(T1 t1_, T2 t2_):
        t1{ t1_ },
        t2{ t2_ }
    {}
    T1 t1;
    T2 t2;
};

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, helper_1436<T1, T2> const& helper) {
    out << "{ " << helper.t1 << ", " << helper.t2 << " }";
    return out;
}

// Clang and gcc have different names for this warning, and clang also
// warns about an unused value
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcomma-subscript"
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-comma-subscript"
#pragma clang diagnostic ignored "-Wunused-value"
#endif

TEST_CASE("CAPTURE can deal with complex expressions involving commas", "[messages][capture]") {
    CAPTURE(std::vector<int>{1, 2, 3}[0, 1, 2],
            std::vector<int>{1, 2, 3}[(0, 1)],
            std::vector<int>{1, 2, 3}[0]);
    CAPTURE((helper_1436<int, int>{12, -12}),
            (helper_1436<int, int>(-12, 12)));
    CAPTURE( (1, 2), (2, 3) );
    SUCCEED();
}

#ifdef __GNUG__
#pragma GCC diagnostic pop
#endif

TEST_CASE("CAPTURE parses string and character constants", "[messages][capture]") {
    CAPTURE(("comma, in string", "escaped, \", "), "single quote in string,',", "some escapes, \\,\\\\");