diff options
| author | Julien Nitard | 2018-05-30 21:32:59 -0500 |
|---|---|---|
| committer | Martin Hořeňovský | 2018-06-06 22:33:03 +0200 |
| commit | 7be8a41adf368b48350e5906568adf34579d4718 (patch) | |
| tree | 4cae0f05235b1e15cd99eed38a6749891ed70473 /projects/SelfTest/UsageTests/ToStringWhich.tests.cpp | |
| parent | 021fcee63667e346c619e04bbae932bcea562334 (diff) | |
| download | catch3-7be8a41adf368b48350e5906568adf34579d4718.tar.gz | |
Fix ambiguity in stringification
Happening when using clang and templated operators, clang cannot decide
between the operator provided by ReusableStringStream and the one provided
by the value value as both are templates. This is easily solved by calling
the operator<< through the member syntax.
Fixes #1285
Diffstat (limited to 'projects/SelfTest/UsageTests/ToStringWhich.tests.cpp')
| -rw-r--r-- | projects/SelfTest/UsageTests/ToStringWhich.tests.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp b/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp index 7be99dcd..26afa3b1 100644 --- a/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp +++ b/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp @@ -20,6 +20,7 @@ struct has_operator { }; struct has_maker {}; struct has_maker_and_operator {}; struct has_neither {}; +struct has_template_operator {}; std::ostream& operator<<(std::ostream& os, const has_operator&) { os << "operator<<( has_operator )"; @@ -31,6 +32,12 @@ std::ostream& operator<<(std::ostream& os, const has_maker_and_operator&) { return os; } +template <typename StreamT> +StreamT& operator<<(StreamT& os, const has_template_operator&) { + os << "operator<<( has_template_operator )"; + return os; +} + namespace Catch { template<> struct StringMaker<has_maker> { @@ -69,6 +76,12 @@ TEST_CASE("stringify( has_neither )", "[toString]") { REQUIRE( ::Catch::Detail::stringify(item) == "{ !!! }" ); } +// Call the templated operator +TEST_CASE( "stringify( has_template_operator )", "[toString]" ) { + has_template_operator item; + REQUIRE( ::Catch::Detail::stringify( item ) == "operator<<( has_template_operator )" ); +} + // Vectors... |