Skip to content

Commit 3a1b47f

Browse files
author
Daniel Kroening
committed
print the source line with the error
1 parent 39dce85 commit 3a1b47f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
const-array.c
33
^.*: .* is constant$
4+
^ array\[1\] = 2;$
45
^EXIT=(1|64)$
56
^SIGNAL=0$
67
--

regression/ansi-c/const1/const-member.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ CORE
22
const-member.c
33

44
^.*: .* is constant$
5+
^ const_struct_ptr->field = 123;$
56
^EXIT=(1|64)$
67
^SIGNAL=0$
78
--

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)