alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization 📊🗾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.11k stars 313 forks source link

c++ 20 Compile error #287

Open ZichaoNickFox opened 1 year ago

ZichaoNickFox commented 1 year ago

Bug category

Describe the bug

c++ 20 unsupport value u8 string to std::string https://stackoverflow.com/questions/56833000/c20-with-u8-char8-t-and-stdstring

Steps to Reproduce

bazel --output_user_root="./.cache" build ^
  --cxxopt="/std:c++20" ^
  --verbose_failures  ^
  //playground:window

Output external/matplotplusplus/source/matplot/core/line_spec.cpp(76): error C2679: binary '=': no operator found which takes a right-hand operand of type 'const char8_t [6]' (or there is no acceptable conversion)

```console ERROR: C:/users/liuzichao/desktop/cg/.cache/in4szefe/external/matplotplusplus/BUILD.bazel:4:12: Compiling source/matplot/core/line_spec.cpp failed: (Exit 2): cl.exe failed: error executing command cd /d C:/users/liuzichao/desktop/cg/.cache/in4szefe/execroot/__main__ SET INCLUDE=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt SET PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\VCPackages;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\bin\Roslyn;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\Performance Tools\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools;C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\\x64;C:\Program Files (x86)\Windows Kits\10\bin\\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\;;C:\WINDOWS\system32;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\Linux\bin\ConnectionManagerExe SET PWD=/proc/self/cwd SET RUNFILES_MANIFEST_ONLY=1 SET TEMP=C:\Users\LIUZIC~1\AppData\Local\Temp SET TMP=C:\Users\LIUZIC~1\AppData\Local\Temp C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /Iexternal/matplotplusplus /Ibazel-out/x64_windows-fastbuild/bin/external/matplotplusplus /Iexternal/matplotplusplus/source /Ibazel-out/x64_windows-fastbuild/bin/external/matplotplusplus/source /Iexternal/matplotplusplus/source/3rd_party/cimg /Ibazel-out/x64_windows-fastbuild/bin/external/matplotplusplus/source/3rd_party/cimg /Iexternal/matplotplusplus/source/3rd_party/nodesoup/include /Ibazel-out/x64_windows-fastbuild/bin/external/matplotplusplus/source/3rd_party/nodesoup/include /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /std:c++20 /Fobazel-out/x64_windows-fastbuild/bin/external/matplotplusplus/_objs/matplotplusplus/line_spec.obj /c external/matplotplusplus/source/matplot/core/line_spec.cpp # Configuration: d105fb13273de9ae46576eea29a2ce04076ea3899394eca8d1fd2ff8c61f51fb # Execution platform: @local_config_platform//:host external/matplotplusplus/source/matplot/core/line_spec.cpp(1): warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss C:\users\liuzichao\desktop\cg\.cache\in4szefe\execroot\__main__\external\matplotplusplus\source\matplot/core/line_spec.h(1): warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss external/matplotplusplus/source/matplot/core/line_spec.cpp(76): error C2001: newline in constant external/matplotplusplus/source/matplot/core/line_spec.cpp(76): error C2679: binary '=': no operator found which takes a right-hand operand of type 'const char8_t [6]' (or there is no acceptable conversion) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3091): note: could be 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const _Elem)' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3083): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const _Elem *const )' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3031): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const std::basic_string,std::allocator> &)' C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(2962): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(std::initializer_list<_Elem>)' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(2826): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(std::basic_string,std::allocator> &&) noexcept()' external/matplotplusplus/source/matplot/core/line_spec.cpp(77): note: while trying to match the argument list '(std::string, const char8_t [6])' external/matplotplusplus/source/matplot/core/line_spec.cpp(77): error C2143: syntax error: missing ';' before 'break' external/matplotplusplus/source/matplot/core/line_spec.cpp(80): error C2679: binary '=': no operator found which takes a right-hand operand of type 'const char8_t [7]' (or there is no acceptable conversion) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3091): note: could be 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const _Elem)' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3083): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const _Elem *const )' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3031): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const std::basic_string,std::allocator> &)' C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(2962): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(std::initializer_list<_Elem>)' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(2826): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(std::basic_string,std::allocator> &&) noexcept()' external/matplotplusplus/source/matplot/core/line_spec.cpp(80): note: while trying to match the argument list '(std::string, const char8_t [7])' external/matplotplusplus/source/matplot/core/line_spec.cpp(392): error C2001: newline in constant external/matplotplusplus/source/matplot/core/line_spec.cpp(392): error C2679: binary '=': no operator found which takes a right-hand operand of type 'const char8_t [6]' (or there is no acceptable conversion) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3091): note: could be 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const _Elem)' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3083): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const _Elem *const )' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3031): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const std::basic_string,std::allocator> &)' C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(2962): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(std::initializer_list<_Elem>)' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(2826): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(std::basic_string,std::allocator> &&) noexcept()' external/matplotplusplus/source/matplot/core/line_spec.cpp(393): note: while trying to match the argument list '(std::string, const char8_t [6])' external/matplotplusplus/source/matplot/core/line_spec.cpp(393): error C2143: syntax error: missing ';' before 'break' external/matplotplusplus/source/matplot/core/line_spec.cpp(396): error C2679: binary '=': no operator found which takes a right-hand operand of type 'const char8_t [7]' (or there is no acceptable conversion) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3091): note: could be 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const _Elem)' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3083): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const _Elem *const )' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(3031): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(const std::basic_string,std::allocator> &)' C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(2962): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(std::initializer_list<_Elem>)' with [ _Elem=char ] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstring(2826): note: or 'std::basic_string,std::allocator> &std::basic_string,std::allocator>::operator =(std::basic_string,std::allocator> &&) noexcept()' external/matplotplusplus/source/matplot/core/line_spec.cpp(396): note: while trying to match the argument list '(std::string, const char8_t [7])' Target //playground:window failed to build INFO: Elapsed time: 37.951s, Critical Path: 33.00s INFO: 15 processes: 9 internal, 6 local. FAILED: Build did NOT complete successfully ```

Platform

Environment Details:

Additional context

WildRackoon commented 1 year ago

Fixes that works on Ubuntu Clang 14, can make it a PR: https://github.com/alandefreitas/matplotplusplus/compare/master...WildRackoon:matplotplusplus:fix-cpp20

alandefreitas commented 1 year ago

Just replacing char/string with char8_t/u8string doesn't look like a general solution because char8_t is a new type breaking the API.

I'm not sure what the best solution for this is yet. This is not the only library where u8 string literals broke things. All solutions look suboptimal because this is something where C++20 is not retroactively compatible with C++17.

DNKpp commented 4 months ago

@alandefreitas As a fix is already present on master, could we get a new release? Or is it intended to directly using master branch as tag (or a commit tag).

alandefreitas commented 4 months ago

Sure: https://github.com/alandefreitas/matplotplusplus/releases/tag/v1.2.1

DNKpp commented 4 months ago

Wow, that was quick. Thank you very much :)