Skip to content

Commit e9903de

Browse files
committed
fixed ifstream::readsome() returning empty in LLVM18 OSX
std::basic_istream<CharT,Traits>::readsome is very implementation specific and was returning empty in LLVM18 OSX. stringstream was used as a in memory stream to allow readsome() to return non-empty
1 parent 1309353 commit e9903de

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tool/schema_compiler/src/Main.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,18 @@ int main(int argc, char **argv)
8989
std::ifstream stream(file);
9090
if (not stream.is_open())
9191
return 1;
92-
93-
auto tokens = minecpp::tool::schema_compiler::lex_input(stream);
92+
/**
93+
* Internal parser uses std::basic_istream<CharT,Traits>::readsome to read from the stream
94+
* which is highly implementation specific and was returning empty on LLVM18 in OSX.
95+
*
96+
* Therefore we create a stringstream to read from the file into memory, where readsome()
97+
* function will then return non-empty, as the contents are in memory.
98+
*
99+
* https://en.cppreference.com/w/cpp/io/basic_istream/readsome
100+
*/
101+
std::stringstream in_memory_stream;
102+
in_memory_stream << stream.rdbuf();
103+
auto tokens = minecpp::tool::schema_compiler::lex_input(in_memory_stream);
94104
minecpp::tool::schema_compiler::Parser parser(tokens);
95105

96106
try {

0 commit comments

Comments
 (0)