Skip to content

Commit a963caa

Browse files
author
Daniel Kroening
committed
print the source line with the error
1 parent d3438a1 commit a963caa

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/util/cout_message.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "cout_message.h"
1010

11+
#include <fstream>
1112
#include <iostream>
1213

1314
#ifdef _WIN32
@@ -185,6 +186,26 @@ void gcc_message_handlert::print(
185186
dest+=message;
186187

187188
print(level, dest);
189+
190+
const auto file_name = location.full_path();
191+
if(file_name.has_value() && !line.empty())
192+
{
193+
#ifdef _WIN32
194+
std::ifstream in(widen(file_name.value()));
195+
#else
196+
std::ifstream in(file_name.value());
197+
#endif
198+
if(in)
199+
{
200+
const auto line_number = std::stoull(id2string(line));
201+
std::string line;
202+
for(std::size_t l = 0; l < line_number; l++)
203+
std::getline(in, line);
204+
205+
if(in)
206+
print(level, " " + line); // gcc adds a space, clang doesn't
207+
}
208+
}
188209
}
189210

190211
void gcc_message_handlert::print(

0 commit comments

Comments
 (0)