Skip to content

[c++] googletest tests fail on newer versions of googletest which dropped C++11 supportΒ #5976

Closed

Description

@yurivict

Description

Failure message:

In file included from /usr/ports/misc/lightgbm/work/LightGBM-4.0.0/tests/cpp_tests/test_main.cpp:5:
In file included from /usr/local/include/gtest/gtest.h:64:
In file included from /usr/local/include/gtest/gtest-assertion-result.h:46:
In file included from /usr/local/include/gtest/gtest-message.h:57:
/usr/local/include/gtest/internal/gtest-port.h:270:2: error: C++ versions less than C++14 are not supported.
#error C++ versions less than C++14 are not supported.
 ^
In file included from /usr/ports/misc/lightgbm/work/LightGBM-4.0.0/tests/cpp_tests/test_main.cpp:5:
In file included from /usr/local/include/gtest/gtest.h:65:
In file included from /usr/local/include/gtest/gtest-death-test.h:43:
In file included from /usr/local/include/gtest/internal/gtest-death-test-internal.h:47:
In file included from /usr/local/include/gtest/gtest-matchers.h:48:
In file included from /usr/local/include/gtest/gtest-printers.h:115:
/usr/local/include/gtest/internal/gtest-internal.h:636:54: error: too few template arguments for class template 'less'
  typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
                                                     ^
/usr/include/c++/v1/__functional/operations.h:366:29: note: template is declared here
struct _LIBCPP_TEMPLATE_VIS less
                            ^
In file included from /usr/ports/misc/lightgbm/work/LightGBM-4.0.0/tests/cpp_tests/test_main.cpp:5:
In file included from /usr/local/include/gtest/gtest.h:65:
In file included from /usr/local/include/gtest/gtest-death-test.h:43:
In file included from /usr/local/include/gtest/internal/gtest-death-test-internal.h:47:
In file included from /usr/local/include/gtest/gtest-matchers.h:48:
In file included from /usr/local/include/gtest/gtest-printers.h:115:
/usr/local/include/gtest/internal/gtest-internal.h:613:22: error: member reference base type 'testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'int') is not a structure or union
    registered_tests_.insert(
    ~~~~~~~~~~~~~~~~~^~~~~~~
/usr/local/include/gtest/internal/gtest-internal.h:619:29: error: member reference base type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'const int') is not a structure or union
    return registered_tests_.count(test_name) > 0;
           ~~~~~~~~~~~~~~~~~^~~~~~
/usr/local/include/gtest/internal/gtest-internal.h:623:5: error: 'testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'int') is not a class, namespace, or enumeration
    RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
    ^
/usr/local/include/gtest/internal/gtest-internal.h:623:62: error: member reference base type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'const int') is not a structure or union
    RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
                                            ~~~~~~~~~~~~~~~~~^~~~~
/usr/local/include/gtest/internal/gtest-internal.h:624:41: error: member reference base type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' (aka 'const int') is not a structure or union
    GTEST_CHECK_(it != registered_tests_.end());
                       ~~~~~~~~~~~~~~~~~^~~~
/usr/local/include/gtest/internal/gtest-port.h:1027:35: note: expanded from macro 'GTEST_CHECK_'
  if (::testing::internal::IsTrue(condition)) \
                                  ^~~~~~~~~
7 errors generated.

Environment info

LightGBM version or commit hash: 4.0.0
clang-15
pytest-7.3.1
FreeBSD 13.2

Activity

  1. jameslamb commented on Jul 14, 2023

    @jameslamb
    Member

    Thanks for using LightGBM.

    Please provide the exact commands you ran which produced this error message. With just an error message, it's difficult for us to help you.

  2. yurivict commented on Jul 14, 2023

    @yurivict
    Author

    Complete log is here.

  3. jameslamb commented on Jul 14, 2023

    @jameslamb
    Member

    Can you explain the context of what this build is? It looks quite complicated.

    For example, what are these patches?

    ===>  Patching for lightgbm-4.0.0
    ===>  Applying FreeBSD patches for lightgbm-4.0.0 from /usr/ports/misc/lightgbm/files
    

    We'd very much appreciate if you could reduce this report to a minimal one that reproduces the problem you're facing.

  4. yurivict commented on Jul 14, 2023

    @yurivict
    Author

    This is a FreeBSD port build.
    The patch applied is:

    --- CMakeLists.txt.orig 2022-12-29 04:59:34 UTC
    +++ CMakeLists.txt
    @@ -507,7 +507,7 @@ endif(__BUILD_FOR_R)
     
     #-- Google C++ tests
     if(BUILD_CPP_TEST)
    -  find_package(GTest CONFIG)
    +  find_package(GTest)
       if(NOT GTEST_FOUND)
         message(STATUS "Did not find Google Test in the system root. Fetching Google Test now...")
         include(FetchContent)
    

    It shouldn't matter for this issue.

    The core problem is that googletest no longer supports c++11, and the project uses c++11. You should change that to c++20, for example.

  5. jameslamb commented on Jul 14, 2023

    @jameslamb
    Member

    Interesting! I guess we haven't experienced that in this project's CI because we don't preinstall googletest, and instead rely on CMake to pull in a specific, fairly-old version.

    https://github.com/microsoft/LightGBM/blob/d73c6b530b39a18a3cacaafc4e42550be853c036/CMakeLists.txt#L607-L617

    That version of googletest still supported C++11. That support was dropped in v1.12.1 (June 30, 2022.

    You should change that to c++20, for example.

    I absolutely don't support dropping C++11, C++14, and C++17 support yet in LightGBM. That would impact a lot of the project's users, and so far we haven't found that maintaining such compatibility has been a major issue. There is some discussion in #5691 if you're curious.

    However... I'd definitely support upgrading to the latest release of googletest and using the C++20 standard when running those tests. That'd give us some minimal test coverage on C++20 (we currently have none) and make it easier for repackagers like you.

    I'll put up a PR for that shortly, thanks for the report and sorry for the inconvenience.

  6. changed the title [-]Tests fail to compile: /usr/local/include/gtest/internal/gtest-port.h:270:2: error: C++ versions less than C++14 are not supported, etc[/-] [+][c++] googletest tests fail on newer versions of googletest which dropped C++11 support[/+] on Jul 14, 2023
  7. added a commit that references this issue on Dec 28, 2023
    b74528f
  8. github-actions commented on Jan 1, 2025

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

  9. locked as resolved and limited conversation to collaborators on Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions