ned14 / llfio

P1031 low level file i/o and filesystem library for the C++ standard
https://ned14.github.io/llfio/
Other
881 stars 45 forks source link

WIN32 clang-cl: 'extern' is invalid in friend declarations #105

Closed BurningEnlightenment closed 1 year ago

BurningEnlightenment commented 1 year ago

Describe the bug clang-cl fails to compile fs_handle.hpp/to_win32_path due to the friend declaration containing the extern linkage specifier.

  In file included from C:\devel\source\deeplex\concrete\build\x64-windows-clang\vcpkg_installed\x64-windows-static\include\llfio/llfio.hpp:18:
  In file included from C:\devel\source\deeplex\concrete\build\x64-windows-clang\vcpkg_installed\x64-windows-static\include\llfio/v2.0/llfio.hpp:65:
  In file included from C:\devel\source\deeplex\concrete\build\x64-windows-clang\vcpkg_installed\x64-windows-static\include\llfio/v2.0/directory_handle.hpp:28:
  In file included from C:\devel\source\deeplex\concrete\build\x64-windows-clang\vcpkg_installed\x64-windows-static\include\llfio/v2.0/path_discovery.hpp:28:
C:\devel\source\deeplex\concrete\build\x64-windows-clang\vcpkg_installed\x64-windows-static\include\llfio\v2.0\fs_handle.hpp(175,12): error : 'extern' is invalid in friend declarations
      friend LLFIO_HEADERS_ONLY_FUNC_SPEC result<filesystem::path>
             ^
  C:\devel\source\deeplex\concrete\build\x64-windows-clang\vcpkg_installed\x64-windows-static\include\llfio/v2.0/config.hpp(464,38): note: expanded from macro 'LLFIO_HEADERS_ONLY_FUNC_SPEC'
  #define LLFIO_HEADERS_ONLY_FUNC_SPEC extern LLFIO_DECL

https://github.com/ned14/llfio/blob/f8d2eebeb1742a5ebec4da856d47ba6fd1a48a8c/include/llfio/v2.0/fs_handle.hpp#L121-L122 https://github.com/ned14/llfio/blob/f8d2eebeb1742a5ebec4da856d47ba6fd1a48a8c/include/llfio/v2.0/fs_handle.hpp#L156-L157

To Reproduce / MCVE

#include <llfio/llfio.hpp>

clang-cl.exe /nologo -TP -DLLFIO_EXPERIMENTAL_STATUS_CODE=1 -DLLFIO_HEADERS_ONLY=0 -DOUTCOME_USE_SYSTEM_STATUS_CODE=1 -DQUICKCPPLIB_ENABLE_VALGRIND=1 -imsvcbuild\x64-windows-clang\vcpkg_installed\x64-windows-static\include /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -MTd -std:c++20 /showIncludes -c -- mcve.cpp

Expected behavior No compiler error.

Environment

Additional context I'm unsure what the preferred fix would be:

There is one additional occurence: https://github.com/ned14/llfio/blob/f8d2eebeb1742a5ebec4da856d47ba6fd1a48a8c/include/llfio/v2.0/detail/impl/posix/test/io_uring_multiplexer.ipp#L100

ned14 commented 1 year ago

Sorry about writing failing code :)

The fix should be easy, declare the function before the friend declaration so it gets the LLFIO_HEADERS_ONLY_FUNC_SPEC, then the friend declaration probably can make do without it. I say "probably" because other compilers may complain if the friend declaration doesn't exactly match the earlier declaration.

Currently at a WG21 meeting in person so time is limited.

BurningEnlightenment commented 1 year ago

The fix should be easy, declare the function before the friend declaration so it gets the LLFIO_HEADERS_ONLY_FUNC_SPEC, then the friend declaration probably can make do without it.

Luckily that declaration already exists at an approppriate place :)

I say "probably" because other compilers may complain if the friend declaration doesn't exactly match the earlier declaration.

That thought kept me from just commit a fix. However, I will just go ahead and prepare a PR.

Currently at a WG21 meeting in person so time is limited.

No worries, clang-cl isn't a primary target platform for me. I've actually procrastinated reporting this for a year or two 😅. So delaying by a week or two doesn't really matter.

Godspeed to you and your proposals.