I have got this code:
#include <fstream>
#include <vector>
int main() {
const std::string path = "/tmp/some_random_path"; // this file do not exist before running of program
std::ofstream file_output(path);
std::ifstream file_input(path, std::ios::in | std::ios::binary);
file_input.peek();
if (!file_input.eof()) {
return 1;
}
std::vector<char> data = {'a', 'b', 'c'};
file_output.write(data.data(), static_cast<long>(data.size()));
file_output.flush();
file_input.clear();
file_input.peek();
if (file_input.eof()) {
return 2; // libc++
}
return 0; // libstdc++11
}
My specs:
lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.4 LTS Release: 20.04 Codename: focal
clang++ -v Ubuntu clang version 15.0.7 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10 Candidate multilib: .;@m64 Selected multilib: .;@m64
libstdc++11 compile command: clang++ main.cpp
libc++ compile command: clang++ -stdlib=libc++ main.cpp
I expect success return code for both libc++ and libstdc++11, but libc++ eof flag is not updated. Is it valid?