From: Jason Merrill Date: Tue, 21 Apr 2026 20:23:37 +0000 (-0400) Subject: c++: #include rewrite and installed compiler [PR123879] X-Git-Tag: basepoints/gcc-17~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=446ed8b4edce048da7201f3f8cd4dbfcce67fb34;p=thirdparty%2Fgcc.git c++: #include rewrite and installed compiler [PR123879] In an installed compiler, the pathname in the expanded_location might be canonicalized while the pathname in the cpp_dir is not, e.g. eloc.file is ".../include/c++/16.0.1/stdbit.h" while dir->name is ".../lib/gcc/x86_64-pc-linux-gnu/16.0.1/../../../../include/c++/16.0.1". So let's use lrealpath to compare canonical paths for both. And filename_ncmp, while we're at it. PR c++/123879 gcc/cp/ChangeLog: * module.cc (maybe_translate_include): Use lrealpath in check whether we're including something in the same directory. --- diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index e5547f7d029..a7245aae46a 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -23131,13 +23131,22 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc, /* Redirect importable to . */ /* ??? Generalize to use a .json. */ expanded_location eloc = expand_location (loc); + auto indir = [](const char *f, const char *d) + { + if (!filename_ncmp (f, d, strlen (d))) return true; + /* Also check canonical paths (c++/123879). */ + auto cf = lrealpath (f); auto cd = lrealpath (d); + bool r = cf && cd && !filename_ncmp (cf, cd, strlen (cd)); + free (cf); free (cd); + return r; + }; if (angle && is_importable_header (fname) /* Exclude which often goes with import std. */ && strcmp (fname, "version") != 0 /* Don't redirect #includes between headers under the same include path directory (i.e. between library headers); if the import brings in the current file we then get redefinition errors. */ - && !strstr (eloc.file, _cpp_get_file_dir (file)->name) + && !indir (eloc.file, _cpp_get_file_dir (file)->name) /* ??? These are needed when running a toolchain from the build directory, because libsupc++ headers aren't linked into libstdc++-v3/include with the other headers. */