std::string_view behavior in modules with cmake

89 Views Asked by At
  • MVSC 14.37.32822
  • Compiler version 19.37.32825

Hi, I have ran into some weird and specific behavior regarding modules, std::string_view and cmake.

The following code only works if I include std::string_view in my main.ixx file. But when writing the same code in Visual Studio (without cmake) it doesn't require me to include the header.

// Logger.ixx
module;

#include <iostream>
#include <format>
#include <string_view>

export module Logger;

export template<typename... Args>
void Log(std::string_view format, Args&&... args)
{
    auto result = std::vformat(format, std::make_format_args(args...));
    std::cout << result << std::endl;
}
// main.ixx
import Logger;

// This is required for the compilation to succeed. But why?
// And why doesn't visual studio need this?
#include <string_view> 

int main() {
    Log("Hello {}", "world");
    return 0;
}

This is the compilation error I get when not including std::string_view in main.ixx My main question is: Why is this happening?

====================[ Build | VulkanEngine | Debug-Visual Studio ]==============
"C:\Program Files\JetBrains\CLion 2023.2.2\bin\cmake\win\x64\bin\cmake.exe" --build C:\Dev\VulkanEngine\cmake-build-debug-visual-studio --target VulkanEngine --config Debug
CMake is re-running because C:/Dev/VulkanEngine/cmake-build-debug-visual-studio/CMakeFiles/generate.stamp is out-of-date.
  the file 'C:/Dev/VulkanEngine/CMakeLists.txt'
  is newer than 'C:/Dev/VulkanEngine/cmake-build-debug-visual-studio/CMakeFiles/generate.stamp.depend'
  result='-1'
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Dev/VulkanEngine/cmake-build-debug-visual-studio
MSBuild version 17.7.2+d6990bcfa for .NET Framework

  Scanning sources for module dependencies...
  main.ixx
  Logger.ixx
  Compiling...
  Logger.ixx
  main.ixx
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\system_error(221,39): error C3774: cannot find 'std::partial_ordering': Please include <compare> header [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Dev\VulkanEngine\main.ixx(5,5): message : see reference to function template instantiation 'void Log<const char(&)[6]>(std::string_view,const char (&)[6])' being compiled [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Dev\VulkanEngine\Logger.ixx(13,10): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(481,39): message : could be 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::basic_streambuf<char,std::char_traits<char>> *)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(449,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(const void *)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(431,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(long double)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(413,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(double)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(395,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(float)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(377,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(unsigned __int64)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(359,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(__int64)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(341,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(unsigned long)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(323,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(long)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(304,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(unsigned int)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(278,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(int)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(259,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(unsigned short)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(225,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(short)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(207,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(bool)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(201,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(195,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::basic_ios<char,std::char_traits<char>> &(__cdecl *)(std::basic_ios<char,std::char_traits<char>> &))' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(190,39): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::basic_ostream<char,std::char_traits<char>> &(__cdecl *)(std::basic_ostream<char,std::char_traits<char>> &))' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(476,20): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::nullptr_t)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Dev\VulkanEngine\Logger.ixx(13,18): message : 'initializing': cannot convert from 'std::string' to 'std::nullptr_t' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Dev\VulkanEngine\Logger.ixx(13,18): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include\ostream(469,20): message : or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(volatile const void *)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Dev\VulkanEngine\Logger.ixx(13,18): message : 'initializing': cannot convert from 'std::string' to 'volatile const void *' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Dev\VulkanEngine\Logger.ixx(13,18): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
C:\Dev\VulkanEngine\Logger.ixx(13,10): message : while trying to match the argument list '(std::basic_ostream<char,std::char_traits<char>>, std::string)' [C:\Dev\VulkanEngine\cmake-build-debug-visual-studio\VulkanEngine.vcxproj]
0

There are 0 best solutions below