Skip to content

clang++ requires '-x c++' with '-emit-module-interface' when compiling a .cppm file #147148

Open
@Iritscen

Description

@Iritscen

Despite .cppm seemingly being labeled as a C++ suffix in the clang source code, clang currently requires -x c++ to be specified when compiling a .cppm file as a module interface. Using the invocation:

clang++ -std=c++20 -Xclang -emit-module-interface -c my_module.cppm -o my_module.pcm

causes clang to emit:

fatal error: module interface compilation does not support input
      file format of file
      '/var/folders/np/v5mwm5js05j85jkcx13r43900000gq/T/my_module-c11c6b.pcm':
      'Precompiled'

However the following invocations work:
clang -cc1 -std=c++20 -emit-module-interface my_module.cppm -o my_module.pcm

and:
clang++ -std=c++20 -Xclang -emit-module-interface -x c++ -c my_module.cppm -o my_module.pcm

and:
clang++ -std=c++20 -c my_module.cppm

The last command is not compiling the source as a .pcm, but the point is that the .cppm file is recognized as C++ without needing to be prompted with '-x c++' unless '-emit-module-interface' is used, with the exception that invoking 'clang -cc1' instead of clang++ works without the -x argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:driver'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions