Skip to content

Commit f247e58

Browse files
authored
fixed #13926 - ErrorMessage::FileLocation::mOrigFileName was not stored in the XML (#7809)
1 parent 301b19d commit f247e58

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/errorlogger.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,20 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
196196
for (const tinyxml2::XMLElement *e = errmsg->FirstChildElement(); e; e = e->NextSiblingElement()) {
197197
const char* name = e->Name();
198198
if (std::strcmp(name,"location")==0) {
199+
const char *strorigfile = e->Attribute("origfile");
199200
const char *strfile = e->Attribute("file");
200201
const char *strinfo = e->Attribute("info");
201202
const char *strline = e->Attribute("line");
202203
const char *strcolumn = e->Attribute("column");
203204

204205
const char *file = strfile ? strfile : unknown;
206+
const char *origfile = strorigfile ? strorigfile : file;
205207
const char *info = strinfo ? strinfo : "";
206208
const int line = strline ? strToInt<int>(strline) : 0;
207209
const int column = strcolumn ? strToInt<int>(strcolumn) : 0;
208-
callStack.emplace_front(file, info, line, column);
210+
callStack.emplace_front(origfile, info, line, column);
211+
if (strorigfile)
212+
callStack.front().setfile(file);
209213
} else if (std::strcmp(name,"symbol")==0) {
210214
mSymbolNames += e->GetText();
211215
}
@@ -508,7 +512,11 @@ std::string ErrorMessage::toXML() const
508512

509513
for (auto it = callStack.crbegin(); it != callStack.crend(); ++it) {
510514
printer.OpenElement("location", false);
511-
printer.PushAttribute("file", it->getfile(false).c_str());
515+
const std::string origfile = it->getOrigFile(false);
516+
const std::string file = it->getfile(false);
517+
if (origfile != file)
518+
printer.PushAttribute("origfile", origfile.c_str());
519+
printer.PushAttribute("file", file.c_str());
512520
printer.PushAttribute("line", std::max(it->line,0));
513521
printer.PushAttribute("column", it->column);
514522
if (!it->getinfo().empty())

test/testerrorlogger.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ class TestErrorLogger : public TestFixture {
409409
message += " <location file=\"bar.cpp\" line=\"8\" column=\"1\" info=\"\\303\\244\"/>\n";
410410
message += " <location file=\"foo.cpp\" line=\"5\" column=\"1\"/>\n";
411411
message += " <location file=\"dir1/a.cpp\" line=\"1\" column=\"1\"/>\n";
412-
message += " <location file=\"dir2/a.cpp\" line=\"1\" column=\"1\"/>\n";
413-
message += " <location file=\"dir3/a.cpp\" line=\"1\" column=\"1\"/>\n";
414-
message += " <location file=\"dir4/a.cpp\" line=\"1\" column=\"1\"/>\n";
412+
message += " <location origfile=\"dir2\\a.cpp\" file=\"dir2/a.cpp\" line=\"1\" column=\"1\"/>\n";
413+
message += " <location origfile=\"dir/a.cpp\" file=\"dir3/a.cpp\" line=\"1\" column=\"1\"/>\n";
414+
message += " <location origfile=\"dir/a.cpp\" file=\"dir4/a.cpp\" line=\"1\" column=\"1\"/>\n";
415415
message += " </error>";
416416
ASSERT_EQUALS(message, msg.toXML());
417417
}
@@ -443,7 +443,7 @@ class TestErrorLogger : public TestFixture {
443443
" hash=\"456\""
444444
">\n"
445445
" <location file=\"bar.cpp\" line=\"8\" column=\"1\"/>\n"
446-
" <location file=\"foo.cpp\" line=\"5\" column=\"2\"/>\n"
446+
" <location origfile=\"proj/foo.cpp\" file=\"foo.cpp\" line=\"5\" column=\"2\"/>\n"
447447
"</error>";
448448
tinyxml2::XMLDocument doc;
449449
ASSERT(doc.Parse(xmldata, sizeof(xmldata)) == tinyxml2::XML_SUCCESS);
@@ -458,9 +458,11 @@ class TestErrorLogger : public TestFixture {
458458
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
459459
ASSERT_EQUALS(456u, msg.hash);
460460
ASSERT_EQUALS(2u, msg.callStack.size());
461+
ASSERT_EQUALS("proj/foo.cpp", msg.callStack.front().getOrigFile(false));
461462
ASSERT_EQUALS("foo.cpp", msg.callStack.front().getfile(false));
462463
ASSERT_EQUALS(5, msg.callStack.front().line);
463464
ASSERT_EQUALS(2u, msg.callStack.front().column);
465+
ASSERT_EQUALS("bar.cpp", msg.callStack.back().getOrigFile(false));
464466
ASSERT_EQUALS("bar.cpp", msg.callStack.back().getfile(false));
465467
ASSERT_EQUALS(8, msg.callStack.back().line);
466468
ASSERT_EQUALS(1u, msg.callStack.back().column);

0 commit comments

Comments
 (0)