From 56736f227817e612c92eeddea2afd4d908b70cef Mon Sep 17 00:00:00 2001 From: Helix Solara Date: Tue, 24 Nov 2026 08:17:53 -0800 Subject: [PATCH] Name the source file in error messages by the path it was given. cppfront printed errors with strip_path(sourcefile), the file name without its folder. Build systems run cppfront in an output folder (CMake custom commands, MSBuild steps), so an IDE reading the build output, such as Visual Studio's Error List or VS Code's problem matchers, can't find the file an error names. Errors now print the source path as cppfront was given it, so a full path stays full and a relative one stays relative. strip_path had no other caller and is removed. Given the full path to sub\bad.cpp2, cppfront used to print "bad.cpp2(3,14): error: ..."; it now prints the full path, and given sub/bad.cpp2 it prints that. All 191 regression tests transpile to the same .cpp and .cpp2.output, since run-tests.sh passes bare file names. No regression test covers a path with folders, which run-tests.sh can't express. Co-Authored-By: Claude Opus 5.5 --- source/common.h | 17 ----------------- source/to_cpp1.h | 5 ++++- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/source/common.h b/source/common.h index 2c822d49e..42174ae95 100644 --- a/source/common.h +++ b/source/common.h @@ -433,23 +433,6 @@ auto _as(auto x) } -// String path prefix from filename -// -auto strip_path(std::string const& file) - -> std::string -{ - auto i = std::ssize(file)-1; - while ( - i >= 0 - && file[i] != '\\' - && file[i] != '/' - ) - { - --i; - } - return {file, _as(i+1)}; -} - //----------------------------------------------------------------------- // diff --git a/source/to_cpp1.h b/source/to_cpp1.h index 9cc5b669d..bd50c091d 100644 --- a/source/to_cpp1.h +++ b/source/to_cpp1.h @@ -7191,7 +7191,10 @@ class cppfront || error != *prev ) { - error.print(std::cerr, strip_path(sourcefile)); + // The path as given, not just the file name, so an IDE can + // open the file even when cppfront runs in another folder + // (as build systems run it, in the output folder) + error.print(std::cerr, sourcefile); } prev = &error; }