mirror of
https://github.com/google/googletest.git
synced 2025-12-11 22:20:00 +08:00
Add test case for object with templated PrintTo on generic type
When PrintTo is defined on a set of types which are accepted with a compile time predicate (using SFINAE), the current implementation fails to compile due to an ambiguous error.
This commit is contained in:
parent
ae90305ed5
commit
10da596ac9
@ -85,6 +85,15 @@ void PrintTo(EnumWithPrintTo e, std::ostream* os) {
|
||||
*os << (e == kEWPT1 ? "kEWPT1" : "invalid");
|
||||
}
|
||||
|
||||
struct StructWithSFINAETemplatePrintToInGlobal {};
|
||||
|
||||
template <typename T,
|
||||
typename = typename std::enable_if<std::is_same<
|
||||
T, StructWithSFINAETemplatePrintToInGlobal>::value>::type>
|
||||
void PrintTo(const T& obj, std::ostream* os) {
|
||||
*os << "StructWithSFINAETemplatePrintToInGlobal";
|
||||
}
|
||||
|
||||
// A class implicitly convertible to BiggestInt.
|
||||
class BiggestIntConvertible {
|
||||
public:
|
||||
@ -173,6 +182,15 @@ void PrintTo(const PrintableViaPrintToTemplate<T>& x, ::std::ostream* os) {
|
||||
*os << "PrintableViaPrintToTemplate: " << x.value();
|
||||
}
|
||||
|
||||
struct StructWithSFINAETemplatePrintToInFoo {};
|
||||
|
||||
template <typename T,
|
||||
typename = typename std::enable_if<std::is_same<
|
||||
T, StructWithSFINAETemplatePrintToInFoo>::value>::type>
|
||||
void PrintTo(const T& obj, std::ostream* os) {
|
||||
*os << "StructWithSFINAETemplatePrintToInFoo";
|
||||
}
|
||||
|
||||
// A user-defined streamable class template in a user namespace.
|
||||
template <typename T>
|
||||
class StreamableTemplateInFoo {
|
||||
@ -1292,6 +1310,16 @@ TEST(PrintReferenceWrapper, Unprintable) {
|
||||
Print(std::cref(up)));
|
||||
}
|
||||
|
||||
TEST(PrintPrintableTypeWithSfinaePrintTo, InGlobalNamespace) {
|
||||
EXPECT_EQ("StructWithSFINAETemplatePrintToInGlobal",
|
||||
Print(StructWithSFINAETemplatePrintToInGlobal()));
|
||||
}
|
||||
|
||||
TEST(PrintPrintableTypeWithSfinaePrintTo, InFooNamespace) {
|
||||
EXPECT_EQ("StructWithSFINAETemplatePrintToInFoo",
|
||||
Print(StructWithSFINAETemplatePrintToInFoo()));
|
||||
}
|
||||
|
||||
// Tests printing user-defined unprintable types.
|
||||
|
||||
// Unprintable types in the global namespace.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user