A system_clock::time_point can't be used to represent all valid values of a 64-bit time_t because nearly half the bits are used up for the nanoseconds part. This makes filesystem::last_write_time() check the time_t values and report an error if it can't be converted to the time_point type. This means we don't get undefined behaviour for files with mtime after the 24th century :-) Thanks to Eric Fiselier for point it out. * include/experimental/bits/fs_fwd.h (file_time_type): Simplify definition. * src/filesystem/ops.cc (file_time): Take error_code parameter and check for overflow. (do_copy_file, last_write_time): Pass error_code in file_time calls. * testsuite/experimental/filesystem/operations/last_write_time.cc: New. * testsuite/util/testsuite_fs.h (scoped_file): Define RAII helper. Tested x86_64-linux, committed to trunk. Backports for this (and some other filesystem changes) to follow soon.