https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125337

            Bug ID: 125337
           Summary: Inconsistent search path for header files and header
                    unit cmi-files
           Product: gcc
           Version: 16.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: joergboe at snafu dot de
  Target Milestone: ---

gcc fails to import a user header unit from different source file locations.

The following files exist:
header.hpp:
  /* empty */

main.cpp
  import "header.hpp";
  int main() {}

src/src1.cpp
  import "../header.hpp";

The following steps are executed:
> g++-16 -x c++-user-header header.hpp -c -std=c++20 -fmodules 
> -flang-info-module-cmi
./header.hpp: note: writing CMI ‘gcm.cache/,/header.hpp.gcm’

> g++-16 main.cpp -c -std=c++20 -fmodules -flang-info-module-cmi
In module imported at main.cpp:1:1:
./header.hpp: note: reading CMI ‘gcm.cache/,/header.hpp.gcm’

g++-16 src/src1.cpp -c -std=c++20 -fmodules -flang-info-module-cmi
In module imported at src/src1.cpp:1:1:
./src/../header.hpp: note: reading CMI ‘gcm.cache/,/src/,,/header.hpp.gcm’
./src/../header.hpp: error: failed to read compiled module: No such file or
directory
./src/../header.hpp: note: compiled module file is
‘gcm.cache/,/src/,,/header.hpp.gcm’
./src/../header.hpp: note: imports must be built before being imported
./src/../header.hpp: fatal error: returning to the gate for a mechanical issue
compilation terminated.


When I change src/src1.cpp to
  import "header.hpp";

The translation of src/src1.cpp fails too:
> g++-16 src/src1.cpp -c -std=c++20 -fmodules -flang-info-module-cmi
src/src1.cpp:1:8: fatal error: header.hpp: No such file or directory
    1 | import "header.hpp";
      |        ^~~~~~~~~~~~
compilation terminated.

I expect the search for CMI files and the search for header files to behave
analogously.

Reply via email to