Skip to content

[FR]: Trying to use std::filesystem::path as a type for testing::TestWithParam results in an endless recursion. #4743

Closed as not planned
@b068931

Description

@b068931

Does the feature exist in the most recent commit?

Either I didn't look hard enough or it does not exist in the most recent commit. At least, the version that Visual Studio uses has this problem. I looked in "gtest-printers.h".

Why do we need this feature?

Google Test supports C++17 as far as I understand. And std::filesystem::path is a type which can theoretically be used for tests against different files, so I would expect it work properly or fail with a meaningful message.

Describe the proposal.

The code gets stuck in a loop: UniversalPrint -> UniversalPrinter -> PrintTo -> DefaultPrintTo -> UniversalPrint until a stackoverflow occurs. It appears that this happens due to the fact that std::filesystem::path gets "printed" as an STL-like container (it has begin and end methods). However, this is the only "container" that I know of that returns itself when you dereference its iterator. This is exactly what results in an endless recursion.

Essentially, if you are trying to print "C:\Users\b068931" as a path, you will be stuck trying to print "C:". Dereferencing begin iterator returned by path "C:" will also return "C:".

I assume that this can be fixed by providing a template specialization for PrintTo function template. Which I could do, but I believe that it should already be included so as to avoid this strange crash.

Is the feature specific to an operating system, compiler, or build system version?

I have checked cppreference to ensure that this is not a Visual Studio's quirk, however they simply list the value that is returned by begin() as "iterator" without further specifying what it should return when dereferenced. I mainly use Visual Studio, so I am not sure how this works on other IDE's or OSes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions