Skip to content

Commit 9ba669e

Browse files
committed
Bump min C++ standard for LLFIO to C++ 17. Before anyone complains,
this has been advertised for a couple of years now in compiler diagnostics that support for non-17 `<filesystem>` was deprecated and would be going away. It has now gone away. Please use a LLFIO from before year 2025 if you want `<filesystem>` or `<memory_resource>` polyfill support.
1 parent 6e6029e commit 9ba669e

File tree

8 files changed

+42
-310
lines changed

8 files changed

+42
-310
lines changed

Build.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ These compilers and OSs are regularly tested by CI:
88
- Visual Studio on Windows
99

1010
Other compilers, architectures and OSs may work, but are not tested regularly.
11-
You will need a working [Filesystem TS](https://en.cppreference.com/w/cpp/experimental/fs)
12-
implementation in your STL, and at least C++ 14.
11+
You will need a working Filesystem implementation in your STL, and at least C++ 17.
1312

1413
LLFIO has your choice of header-only, static library, and shared library build modes.
1514
Note that on Microsoft Windows, the default header only configuration is unsafe

CMakeLists.txt

+18-135
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,13 @@ endif()
183183
include(QuickCppLibApplyDefaultDefinitions)
184184

185185
# Set the C++ features this library requires
186-
all_compile_features(PUBLIC
187-
# cxx_exceptions ## Annoyingly not supported by cmake 3.6
188-
cxx_alias_templates
189-
cxx_variadic_templates
190-
cxx_noexcept
191-
cxx_constexpr
192-
cxx_lambda_init_captures
193-
cxx_attributes
194-
cxx_generic_lambdas
195-
)
196-
if(NOT MSVC OR CMAKE_VERSION VERSION_GREATER 3.59)
197-
all_compile_features(PUBLIC
198-
cxx_variable_templates
199-
)
200-
endif()
186+
all_compile_features(PUBLIC cxx_std_17)
201187
set(check_cxx_source_linkage_flags)
202-
# If on VS2019 16.3 or later, or on Apple, we require C++ 17
203-
if((MSVC AND MSVC_VERSION VERSION_GREATER_EQUAL 1923) OR APPLE)
204-
all_compile_features(PUBLIC
205-
cxx_std_17
206-
)
207-
if(NOT CMAKE_CXX_STANDARD)
208-
if(MSVC)
209-
set(check_cxx_source_linkage_flags /std:c++17)
210-
else()
211-
set(check_cxx_source_linkage_flags -std=c++17)
212-
endif()
188+
if(NOT CMAKE_CXX_STANDARD)
189+
if(MSVC)
190+
set(check_cxx_source_linkage_flags /std:c++17)
191+
else()
192+
set(check_cxx_source_linkage_flags -std=c++17)
213193
endif()
214194
endif()
215195
# Set the library dependencies this library has
@@ -264,93 +244,7 @@ int main() {
264244
}
265245
" CXX_HAS_CXX17_FILESYSTEM)
266246
if(NOT CXX_HAS_CXX17_FILESYSTEM)
267-
check_cxx_source_linkage("
268-
#include <experimental/filesystem>
269-
int main() {
270-
try { return std::experimental::filesystem::path(\"hi\").empty(); } catch(std::experimental::filesystem::filesystem_error) { return 1; }
271-
}
272-
" CXX_HAS_CXX_EXPERIMENTAL_FILESYSTEM)
273-
endif()
274-
if(NOT CXX_HAS_CXX17_FILESYSTEM AND NOT CXX_HAS_CXX_EXPERIMENTAL_FILESYSTEM)
275-
indented_message(STATUS "NOTE: Standard <filesystem> not found in the current compiler configuration (try forcing C++ 17 or later?), attempting to figure out what <experimental/filesystem> linker flags to use for this STL ...")
276-
# Are we on libstdc++ or libc++?
277-
check_cxx_source_compiles("
278-
#include <iostream>
279-
int main() {
280-
#ifdef __GLIBCXX__
281-
std::cout << \"hi\";
282-
return 0;
283-
#else
284-
return i am not a number;
285-
#endif
286-
}
287-
" CXX_IS_USING_LIBSTDCXX)
288-
check_cxx_source_compiles("
289-
#include <iostream>
290-
int main() {
291-
#ifdef _LIBCPP_VERSION
292-
std::cout << \"hi\";
293-
return 0;
294-
#else
295-
return i am not a number;
296-
#endif
297-
}
298-
" CXX_IS_USING_LIBCXX)
299-
if(NOT CXX_IS_USING_LIBSTDCXX AND NOT CXX_IS_USING_LIBCXX)
300-
indented_message(FATAL_ERROR "FATAL: <filesystem> is not available, and neither libstdc++ nor libc++ STLs will link a program")
301-
endif()
302-
set(stl_filesystem_link_flags)
303-
# If on libstdc++, we need to link in stdc++fs for experimental filesystem
304-
if(CXX_IS_USING_LIBSTDCXX)
305-
find_library(libstdcxx_stdcxxfs stdc++fs)
306-
if(libstdcxx_stdcxxfs MATCHES "NOTFOUND")
307-
set(libstdcxx_stdcxxfs -lstdc++fs)
308-
endif()
309-
all_link_libraries(PUBLIC ${libstdcxx_stdcxxfs})
310-
list(APPEND stl_filesystem_link_flags ${libstdcxx_stdcxxfs})
311-
endif()
312-
# If on libc++, we may need to link in c++fs or c++experimental for experimental filesystem
313-
if(CXX_IS_USING_LIBCXX)
314-
find_library(libcxx_cxxfs c++fs)
315-
find_library(libcxx_cxxexperimental c++experimental)
316-
if(libcxx_cxxfs MATCHES "NOTFOUND" AND libcxx_cxxexperimental MATCHES "NOTFOUND")
317-
# I guess default to forcing libc++experimental?
318-
set(libcxx_cxxexperimental -lc++experimental)
319-
endif()
320-
if(NOT libcxx_cxxfs MATCHES "NOTFOUND")
321-
all_link_libraries(PUBLIC ${libcxx_cxxfs})
322-
list(APPEND stl_filesystem_link_flags ${libcxx_cxxfs})
323-
endif()
324-
if(NOT libcxx_cxxexperimental MATCHES "NOTFOUND")
325-
all_link_libraries(PUBLIC ${libcxx_cxxexperimental})
326-
list(APPEND stl_filesystem_link_flags ${libcxx_cxxexperimental})
327-
endif()
328-
# Disable the irritating warnings
329-
all_compile_definitions(PUBLIC _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM=1)
330-
endif()
331-
function(check_stl_filesystem_link_flags)
332-
indented_message(STATUS "NOTE: Using STL link flags '${ARGN}'")
333-
set(CMAKE_REQUIRED_LIBRARIES ${ARGN})
334-
check_cxx_source_linkage("
335-
#include <filesystem>
336-
int main() {
337-
try { return std::filesystem::path(\"hi\").empty(); } catch(std::filesystem::filesystem_error) { return 1; }
338-
}
339-
" CXX_HAS_CXX_FILESYSTEM_AFTER_FLAGS)
340-
check_cxx_source_linkage("
341-
#include <experimental/filesystem>
342-
int main() {
343-
try { return std::experimental::filesystem::path(\"hi\").empty(); } catch(std::experimental::filesystem::filesystem_error) { return 1; }
344-
}
345-
" CXX_HAS_CXX_EXPERIMENTAL_FILESYSTEM_AFTER_FLAGS)
346-
if(NOT CXX_HAS_CXX_FILESYSTEM_AFTER_FLAGS AND NOT CXX_HAS_CXX_EXPERIMENTAL_FILESYSTEM_AFTER_FLAGS)
347-
indented_message(FATAL_ERROR "FATAL: After probing multiple configurations, still cannot compile and link a <filesystem> or <experimental/filesystem> based program! Please adjust the configuration and/or install missing dependencies.")
348-
endif()
349-
endfunction()
350-
check_stl_filesystem_link_flags(${stl_filesystem_link_flags})
351-
if(NOT CXX_HAS_CXX_FILESYSTEM_AFTER_FLAGS AND CXX_HAS_CXX_EXPERIMENTAL_FILESYSTEM_AFTER_FLAGS)
352-
all_compile_definitions(PUBLIC LLFIO_FORCE_EXPERIMENTAL_FILESYSTEM=1 KERNELTEST_FORCE_EXPERIMENTAL_FILESYSTEM=1)
353-
endif()
247+
indented_message(FATAL_ERROR "FATAL: C++ 17 <filesystem> is not available, use a LLFIO from before year 2025 if you want legacy <filesystem> polyfill support")
354248
endif()
355249
if(LLFIO_FORCE_DYNAMIC_THREAD_POOL_GROUP_OFF)
356250
all_compile_definitions(PUBLIC LLFIO_EXCLUDE_DYNAMIC_THREAD_POOL_GROUP=1)
@@ -424,18 +318,7 @@ foreach(special ${SPECIAL_BUILDS})
424318
target_compile_definitions(llfio_dl-${special} PRIVATE LLFIO_SOURCE=1 LLFIO_DYN_LINK=1)
425319
endforeach()
426320
if(TARGET llfio-example_single-header)
427-
set(compiler_has_cxx_17 0)
428-
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
429-
if(feature STREQUAL "cxx_std_17")
430-
set(compiler_has_cxx_17 1)
431-
endif()
432-
endforeach()
433-
# The single header test requires C++ 17
434-
if(compiler_has_cxx_17)
435-
target_compile_features(llfio-example_single-header PRIVATE cxx_std_17)
436-
else()
437-
set_target_properties(llfio-example_single-header PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT_BUILD ON)
438-
endif()
321+
target_compile_features(llfio-example_single-header PRIVATE cxx_std_17)
439322
endif()
440323

441324
if(NOT llfio_IS_DEPENDENCY AND (NOT DEFINED BUILD_TESTING OR BUILD_TESTING))
@@ -546,29 +429,29 @@ if(NOT llfio_IS_DEPENDENCY AND (NOT DEFINED BUILD_TESTING OR BUILD_TESTING))
546429
if(UNIT_TESTS_CXX_VERSION STREQUAL "latest")
547430
set(LATEST_CXX_FEATURE)
548431
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
549-
if(feature STREQUAL "cxx_std_23")
432+
if(feature STREQUAL "cxx_std_26")
550433
if(NOT MSVC OR MSVC_VERSION VERSION_GREATER_EQUAL 1930)
551-
set(LATEST_CXX_FEATURE "cxx_std_23")
552-
indented_message(STATUS "NOTE: This compiler claims to support C++ 23, enabling for header-only unit test suite")
434+
set(LATEST_CXX_FEATURE "cxx_std_26")
435+
indented_message(STATUS "NOTE: This compiler claims to support C++ 26, enabling for header-only unit test suite")
553436
endif()
554437
endif()
555438
endforeach()
556439
if(NOT LATEST_CXX_FEATURE)
557440
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
558-
if(feature STREQUAL "cxx_std_20")
441+
if(feature STREQUAL "cxx_std_23")
559442
if(NOT MSVC OR MSVC_VERSION VERSION_GREATER_EQUAL 1930)
560-
set(LATEST_CXX_FEATURE "cxx_std_20")
561-
indented_message(STATUS "NOTE: This compiler claims to support C++ 20, enabling for header-only unit test suite")
443+
set(LATEST_CXX_FEATURE "cxx_std_23")
444+
indented_message(STATUS "NOTE: This compiler claims to support C++ 23, enabling for header-only unit test suite")
562445
endif()
563446
endif()
564447
endforeach()
565448
endif()
566449
if(NOT LATEST_CXX_FEATURE)
567450
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
568-
if(feature STREQUAL "cxx_std_17")
569-
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0")
570-
set(LATEST_CXX_FEATURE "cxx_std_17")
571-
indented_message(STATUS "NOTE: This compiler claims to support C++ 17, enabling for header-only unit test suite")
451+
if(feature STREQUAL "cxx_std_20")
452+
if(NOT MSVC OR MSVC_VERSION VERSION_GREATER_EQUAL 1930)
453+
set(LATEST_CXX_FEATURE "cxx_std_20")
454+
indented_message(STATUS "NOTE: This compiler claims to support C++ 20, enabling for header-only unit test suite")
572455
endif()
573456
endif()
574457
endforeach()

Readme.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ as Intel Optane.
2121

2222
It is a complete rewrite after a Boost peer review in August 2015. LLFIO is the
2323
reference implementation for these C++ standardisations:
24-
- `llfio::path_view` is expected to enter the C++ 26 standard ([P1030](https://wg21.link/p1030)).
25-
- `llfio::file_handle` and `llfio::mapped_file_handle` are on track for entering the C++ 26 standard ([P1883](https://wg21.link/p1883)).
24+
- `llfio::path_view` is expected to enter the C++ 29 standard ([P1030](https://wg21.link/p1030)).
2625

2726
Other characteristics:
28-
- Portable to any conforming C++ 14 compiler with a working Filesystem TS in its STL.
29-
- Note that VS2019 16.3 and libc++ 11 dropped support for Filesystem in C++ 14, so for those LLFIO's cmake forces on C++ 17.
27+
- Portable to any conforming C++ 17 compiler with a working Filesystem in its STL.
3028
- Fully clean with C++ 20.
31-
- Will make use of any Coroutines, Concepts, Span, Byte etc if you have them, otherwise swaps in C++ 14 compatible alternatives.
32-
- NOTE that Ubuntu 18.04's libstdc++ 9 does not currently provide symbols for `<codecvt>` if you are building in C++ 20, so linking LLFIO programs on libstdc++ on that Linux if in C++ 20 will fail. Either use a different STL, manually rebuild libstdc++, or use C++ 17.
29+
- Will make use of any Coroutines, Concepts, Span, Byte etc if you have them, otherwise swaps in C++ 17 compatible alternatives.
3330
- Aims to support Microsoft Windows, Linux, Android, iOS, Mac OS and FreeBSD.
3431
- Best effort to support older kernels up to their EOL (as of July 2020: >= Windows 8.1, >= Linux 2.6.32 (RHEL EOL), >= Mac OS 10.13, >= FreeBSD 11).
3532
- Original error code is always preserved, even down to the original NT kernel error code if a NT kernel API was used.

example/wg21_path_view_benchmark.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Traversal test for path_view (longer paths) ...
4747
#include "../include/llfio.hpp"
4848
#include "llfio/v2.0/directory_handle.hpp"
4949

50-
#if !defined(_WIN32) && (__cplusplus >= 201700L || _HAS_CXX17)
50+
#if !defined(_WIN32)
5151

5252
#include <atomic>
5353
#include <chrono>

include/llfio/v2.0/config.hpp

+15-80
Original file line numberDiff line numberDiff line change
@@ -135,32 +135,15 @@ Distributed under the Boost Software License, Version 1.0.
135135
#include "quickcpplib/cpp_feature.h"
136136

137137
#ifndef STANDARDESE_IS_IN_THE_HOUSE
138-
#ifndef __cpp_alias_templates
139-
#error LLFIO needs template alias support in the compiler
140-
#endif
141-
#ifndef __cpp_variadic_templates
142-
#error LLFIO needs variadic template support in the compiler
143-
#endif
144-
#if __cpp_constexpr < 201304L && !defined(_MSC_VER)
145-
#error LLFIO needs relaxed constexpr (C++ 14) support in the compiler
146-
#endif
147-
#ifndef __cpp_init_captures
148-
#error LLFIO needs lambda init captures support in the compiler (C++ 14)
149-
#endif
150-
#ifndef __cpp_attributes
151-
#error LLFIO needs attributes support in the compiler
152-
#endif
153-
#ifndef __cpp_variable_templates
154-
#error LLFIO needs variable template support in the compiler
155-
#endif
156-
#ifndef __cpp_generic_lambdas
157-
#error LLFIO needs generic lambda support in the compiler
138+
#if !(_HAS_CXX17 || __cplusplus >= 201700)
139+
#error "LLFIO needs a minimum of C++ 17 support in the compiler"
158140
#endif
159141
#ifdef __has_include
160-
// clang-format off
161-
#if !__has_include(<filesystem>) && !__has_include(<experimental/filesystem>)
162-
// clang-format on
163-
#error LLFIO needs an implementation of the Filesystem TS in the standard library
142+
#if !__has_include(<filesystem>)
143+
#error "LLFIO needs an implementation of C++ 17 <filesystem> in the standard library"
144+
#endif
145+
#if !__has_include(<memory_resource>)
146+
#error "LLFIO needs an implementation of C++ 17 <memory_resource> in the standard library"
164147
#endif
165148
#endif
166149
#endif
@@ -242,60 +225,11 @@ LLFIO_V2_NAMESPACE_END
242225
#endif
243226
#include "quickcpplib/utils/thread.hpp"
244227
// Bring in filesystem
245-
#if defined(__has_include)
246-
// clang-format off
247-
#if !LLFIO_FORCE_EXPERIMENTAL_FILESYSTEM && __has_include(<filesystem>) && (__cplusplus >= 201700 || _HAS_CXX17)
248-
#define LLFIO_USING_STD_FILESYSTEM 1
249-
#include <filesystem>
250-
LLFIO_V2_NAMESPACE_BEGIN
251-
namespace filesystem = std::filesystem;
252-
LLFIO_V2_NAMESPACE_END
253-
// C++ 14 filesystem support was dropped in VS2019 16.3
254-
// C++ 14 filesystem support was dropped in LLVM 11
255-
#elif __has_include(<experimental/filesystem>) && (!defined(_MSC_VER) || _MSC_VER < 1923) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 11000)
256-
#define LLFIO_USING_EXPERIMENTAL_FILESYSTEM 1
257-
#include <experimental/filesystem>
258-
LLFIO_V2_NAMESPACE_BEGIN
259-
namespace filesystem = std::experimental::filesystem;
260-
LLFIO_V2_NAMESPACE_END
261-
#elif !LLFIO_FORCE_EXPERIMENTAL_FILESYSTEM && __has_include(<filesystem>)
262-
#if defined(_MSC_VER) && _MSC_VER >= 1923
263-
#error MSVC dropped support for C++ 14 <filesystem> from VS2019 16.3 onwards. Please enable C++ 17 or later.
264-
#endif
265-
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 11000
266-
#error libc++ dropped support for C++ 14 <filesystem> from LLVM 11 onwards. Please enable C++ 17 or later.
267-
#endif
268-
#define LLFIO_USING_STD_FILESYSTEM 1
269-
#include <filesystem>
270-
LLFIO_V2_NAMESPACE_BEGIN
271-
namespace filesystem = std::filesystem;
272-
LLFIO_V2_NAMESPACE_END
273-
#endif
274-
#elif __PCPP_ALWAYS_TRUE__
275228
#define LLFIO_USING_STD_FILESYSTEM 1
276229
#include <filesystem>
277230
LLFIO_V2_NAMESPACE_BEGIN
278231
namespace filesystem = std::filesystem;
279-
LLFIO_V2_NAMESPACE_END
280-
// clang-format on
281-
#elif defined(_MSC_VER)
282-
#define LLFIO_USING_STD_FILESYSTEM 1
283-
#include <filesystem>
284-
LLFIO_V2_NAMESPACE_BEGIN
285-
namespace filesystem = std::experimental::filesystem;
286-
LLFIO_V2_NAMESPACE_END
287-
#else
288-
#error No <filesystem> implementation found
289-
#endif
290-
#if LLFIO_USING_EXPERIMENTAL_FILESYSTEM && !LLFIO_DISABLE_USING_EXPERIMENTAL_FILESYSTEM_WARNING
291-
#ifdef _MSC_VER
292-
#pragma message( \
293-
"WARNING: LLFIO is using the experimental Filesystem TS instead of the standard Filesystem, there are many corner case surprises in the former! Support for the Experimental Filesystem TS is expected to be deprecated at some point, and C++ 17 shall become the minimum required for LLFIO.")
294-
#else
295-
#warning WARNING: LLFIO is using the experimental Filesystem TS instead of the standard Filesystem, there are many corner case surprises in the former! Support for the Experimental Filesystem TS is expected to be deprecated at some point, and C++ 17 shall become the minimum required for LLFIO.
296-
#endif
297-
#endif
298-
LLFIO_V2_NAMESPACE_BEGIN
232+
299233
struct path_hasher
300234
{
301235
size_t operator()(const filesystem::path &p) const { return std::hash<filesystem::path::string_type>()(p.native()); }
@@ -370,9 +304,9 @@ LLFIO_V2_NAMESPACE_BEGIN
370304
using namespace QUICKCPPLIB_NAMESPACE::span;
371305
LLFIO_V2_NAMESPACE_END
372306
// Bring in an optional implementation
373-
#include "quickcpplib/optional.hpp"
307+
#include <optional>
374308
LLFIO_V2_NAMESPACE_BEGIN
375-
using namespace QUICKCPPLIB_NAMESPACE::optional;
309+
template <class T> using optional = std::optional<T>;
376310
LLFIO_V2_NAMESPACE_END
377311
// Bring in a byte implementation
378312
#include "quickcpplib/byte.hpp"
@@ -381,9 +315,10 @@ using QUICKCPPLIB_NAMESPACE::byte::byte;
381315
using QUICKCPPLIB_NAMESPACE::byte::to_byte;
382316
LLFIO_V2_NAMESPACE_END
383317
// Bring in a string_view implementation
384-
#include "quickcpplib/string_view.hpp"
318+
#include <string_view>
385319
LLFIO_V2_NAMESPACE_BEGIN
386-
using namespace QUICKCPPLIB_NAMESPACE::string_view;
320+
template <class CharT, class Traits = std::char_traits<CharT>> using basic_string_view = std::basic_string_view<CharT, Traits>;
321+
using std::string_view;
387322
LLFIO_V2_NAMESPACE_END
388323
// Bring in a function_ptr implementation
389324
#include "quickcpplib/function_ptr.hpp"
@@ -424,9 +359,9 @@ using spinlock = QUICKCPPLIB_NAMESPACE::configurable_spinlock::spinlock<uintptr_
424359
using QUICKCPPLIB_NAMESPACE::configurable_spinlock::lock_guard;
425360
LLFIO_V2_NAMESPACE_END
426361
// Bring in a memory resource implementation
427-
#include "quickcpplib/memory_resource.hpp"
362+
#include <memory_resource>
428363
LLFIO_V2_NAMESPACE_BEGIN
429-
namespace pmr = QUICKCPPLIB_NAMESPACE::pmr;
364+
namespace pmr = std::pmr;
430365
LLFIO_V2_NAMESPACE_END
431366

432367

include/llfio/v2.0/detail/impl/windows/fs_handle.ipp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ LLFIO_HEADERS_ONLY_FUNC_SPEC result<filesystem::path> to_win32_path(const fs_han
10401040
{
10411041
// Are any segments of the filename a reserved name?
10421042
static
1043-
#if(_HAS_CXX17 || __cplusplus >= 201700) && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20170519) // libstdc++'s string_view is missing constexpr
1043+
#if(!defined(__GLIBCXX__) || __GLIBCXX__ > 20170519) // libstdc++'s string_view is missing constexpr
10441044
constexpr
10451045
#endif
10461046
const wstring_view reserved_names[] = {L"\\CON\\", L"\\PRN\\", L"\\AUX\\", L"\\NUL\\", L"\\COM1\\", L"\\COM2\\", L"\\COM3\\", L"\\COM4\\",

0 commit comments

Comments
 (0)