teslamotors / fixed-containers

C++ Fixed Containers
MIT License
361 stars 31 forks source link

Error: Compiling with MSVC #1

Closed abeimler closed 2 years ago

abeimler commented 2 years ago

Hello, I have some problems compiling fixed-containers on Windows, after updating the library in my project. (from 7725f0141aecddcf26118f059d952050bda73383 (Jun. 2021) to the newses 62e81fb596116485247d653b779501ed10a97843 (Oct. 2021)) I only use FixedVector, EnumMap and EnumSet

Now I get this Error:

Error   C7599   'fixed_containers::IteratorConstness::IteratorConstness': a trailing requires clause is only allowed on a templated fixed_containers\iterator_utils.hpp 16  
Error   C2891   'CONSTNESS': cannot take the address of a template parameter    fixed_containers\bidirectional_iterator.hpp 29  

So I pulled this project with all the tests, try to build it and got the same errors.

Steps to Reproduce:

  1. git clone https://github.com/teslamotors/fixed-containers
  2. cd fixed-containers
  3. Install dependencies:
                 git submodule add https://github.com/Microsoft/vcpkg.git vcpkg
                 ./vcpkg/bootstrap-vcpkg.bat
                 ./vcpkg/vcpkg install magic-enum ms-gsl range-v3 gtest
  4. Configure and Build:
                  mkdir build
                  cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake
                  cmake --build build

    Had to modify the dependencies in the CMakeList.txt for vcpkg to work:

find_package(magic_enum CONFIG REQUIRED)

find_package(Microsoft.GSL CONFIG REQUIRED)

find_package(range-v3 CONFIG REQUIRED)

find_package(GTest CONFIG REQUIRED)

macro(add_test_dependencies TEST_TARGET) target_link_libraries(${TEST_TARGET} PRIVATE magic_enum::magic_enum) target_link_libraries(${TEST_TARGET} PRIVATE GTest::gtest GTest::gtest_main)

target_link_libraries(${TEST_TARGET} PRIVATE Microsoft.GSL::GSL)

#target_link_libraries(${TEST_TARGET} PRIVATE range-v3 range-v3-meta range-v3::meta range-v3-concepts)

target_include_directories(${TEST_TARGET} PRIVATE include)
add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET})

endmacro()


### Environment:

 * **OS:** Windows 10
 * **Compiler:** MSVC 19.29.30136.0
 * **IDE:** Visual Studio 2019

## Error

**Compiler-Error:**
```bash
Error   C7599   'fixed_containers::IteratorConstness::IteratorConstness': a trailing requires clause is only allowed on a templated function    fixed-containers\include\fixed_containers\iterator_utils.hpp    16  
Error   C7599   'fixed_containers::IteratorDirection::IteratorDirection': a trailing requires clause is only allowed on a templated function    fixed-containers\include\fixed_containers\iterator_utils.hpp    88  
Error   C2891   'CONSTNESS': cannot take the address of a template parameter    fixed-containers\include\fixed_containers\bidirectional_iterator.hpp    29  
Error   C2891   'CONSTNESS': cannot take the address of a template parameter    fixed-containers\include\fixed_containers\bidirectional_iterator.hpp    35  
Error   C2891   'CONSTNESS': cannot take the address of a template parameter    fixed-containers\include\fixed_containers\bidirectional_iterator.hpp    38  
Error   C2891   'CONSTNESS': cannot take the address of a template parameter    fixed-containers\include\fixed_containers\random_access_iterator_transformer.hpp    30  
Error   C2891   'CONSTNESS': cannot take the address of a template parameter    fixed-containers\include\fixed_containers\random_access_iterator_transformer.hpp    37  
Error   C2891   'CONSTNESS': cannot take the address of a template parameter  fixed_containers\random_access_iterator_transformer.hpp   40  
Error   C2891   'CONSTNESS': cannot take the address of a template parameter    fixed-containers\include\fixed_containers\random_access_iterator_transformer.hpp    41  
Error   C7599   'fixed_containers::fixed_red_black_tree_detail::RedBlackTreeNodeColorCompactness::RedBlackTreeNodeColorCompactness': a trailing requires clause is only allowed on a templated function fixed-containers\include\fixed_containers\fixed_red_black_tree_nodes.hpp    20  
Error   C2891   'COMPACTNESS': cannot take the address of a template parameter  fixed-containers\include\fixed_containers\fixed_red_black_tree_nodes.hpp    292 
Error   C2891   'COMPACTNESS': cannot take the address of a template parameter  fixed-containers\include\fixed_containers\fixed_red_black_tree_storage.hpp  59  
....

Side Note:

  1. Other Compiler Error I found with MSVC:
    Error   C7595   'fixed_containers::StringLiteral::StringLiteral': call to immediate function is not a constant expression    fixed-containers\include\fixed_containers\string_literal.hpp   38  

Easy fix, just set members in the initializer list:

constexpr StringLiteral() noexcept
  : size_(0)
  , cstr_("")
{
}
  1. current fixed-containers works fine with Linux and clang-compiler (compiled my other project in Linux and it works fine)
  2. tried to compile with clang on Windows, had some problems running clang on Windows in Visual Studio 2019
alexkaratarakis commented 2 years ago

Thanks for the detailed write-up! I will investigate these issues.

alexkaratarakis commented 2 years ago

This is now fixed. Latest main builds cleanly with msvc and gcc.