With recent OS upgrade I noticed that small part of my code stopped compiling - it seems the reason is switching from g++-8 to g++-9.
This code is compiling alright on g++ 8.3.0 (verified this using gcc:8.3 image from Dockerhub)
#include <filesystem>
#include <chrono>
int main() {
namespace fs = std::filesystem;
using namespace std::chrono_literals;
std::filesystem::last_write_time("test", std::chrono::system_clock::now() - 5min);
}
On g++ 9.1.0 it fails with:
test.cpp: In function 'int main()':
test.cpp:8:69: error: no matching function for call to 'last_write_time(const char [5], std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >)'
8 | fs::last_write_time("test", std::chrono::system_clock::now() - 5min);
| ^
In file included from /usr/local/include/c++/9.1.0/filesystem:39,
from test.cpp:1:
/usr/local/include/c++/9.1.0/bits/fs_ops.h:243:19: note: candidate: 'std::filesystem::file_time_type std::filesystem::last_write_time(const std::filesystem::__cxx11::path&)'
243 | file_time_type last_write_time(const path& __p);
| ^~~~~~~~~~~~~~~
/usr/local/include/c++/9.1.0/bits/fs_ops.h:243:19: note: candidate expects 1 argument, 2 provided
/usr/local/include/c++/9.1.0/bits/fs_ops.h:244:19: note: candidate: 'std::filesystem::file_time_type std::filesystem::last_write_time(const std::filesystem::__cxx11::path&, std::error_code&)'
244 | file_time_type last_write_time(const path& __p, error_code& __ec) noexcept;
| ^~~~~~~~~~~~~~~
In file included from /usr/local/include/c++/9.1.0/filesystem:36,
from test.cpp:1:
/usr/local/include/c++/9.1.0/bits/fs_fwd.h:362:47: note: no known conversion for argument 2 from 'std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >' to 'std::error_code&'
362 | file_time_type last_write_time(const path&, error_code&) noexcept;
| ^~~~~~~~~~~
In file included from /usr/local/include/c++/9.1.0/filesystem:39,
from test.cpp:1:
/usr/local/include/c++/9.1.0/bits/fs_ops.h:245:8: note: candidate: 'void std::filesystem::last_write_time(const std::filesystem::__cxx11::path&, std::filesystem::file_time_type)'
245 | void last_write_time(const path& __p, file_time_type __new_time);
| ^~~~~~~~~~~~~~~
/usr/local/include/c++/9.1.0/bits/fs_ops.h:245:56: note: no known conversion for argument 2 from 'time_point<std::chrono::_V2::system_clock,[...]>' to 'time_point<std::filesystem::__file_clock,[...]>'
245 | void last_write_time(const path& __p, file_time_type __new_time);
| ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/local/include/c++/9.1.0/bits/fs_ops.h:246:8: note: candidate: 'void std::filesystem::last_write_time(const std::filesystem::__cxx11::path&, std::filesystem::file_time_type, std::error_code&)'
246 | void last_write_time(const path& __p, file_time_type __new_time,
| ^~~~~~~~~~~~~~~
/usr/local/include/c++/9.1.0/bits/fs_ops.h:246:8: note: candidate expects 3 arguments, 2 provided
shell returned 1
Press ENTER or type command to continue
Compile command: g++ -std=c++17 test.cpp -lstdc++-fs (even though linking stdc++-fs is unnecessary on since g++9)
My question is - what is the idiomatic use of this function the way I intended? Namely changing the last write time of a file to five minutes ago.
I understand I used this in somehow non-idiomatic way if a breaking change was introduced.