Alex Vergara
Alex Vergara

Reputation: 2278

Clang error including headers in C++ projects

C++ project, using Clang on it's version 14, Windows as OS and with the language level up to c++20.

So take the next code:

#include <iostream>
import builder;

int main(int argc, char const *argv[])
{
    std::cout << "Value: " << say_hi() << std::endl;
    std::cout << "Hi, from the C++ design patterns project" << std::endl;
    return 0;
}

main.cpp compiled with: clang++ --std=c++20 -stdlib=libc++ -fmodules -fimplicit-modules -fbuiltin-module-map -fimplicit-module-maps -o ./out/cpp-design-patterns code/main.cpp ./out/modules/interfaces/builder.pcm -fprebuilt-module-path=./out/modules/interfaces

and the module interface unit:

module;

#include <string>

export module builder;

export {
    const std::string say_hi() noexcept {
        return std::string {"Saying hi with std::string!"};
    }
}

builder.cppm generating the precompiled header unit with: clang++ -c --std=c++20 -stdlib=libc++ -Xclang -emit-module-interface --precompile -o ./out/modules/interfaces/builder.pcm ./code/ifc/builder.cppm

And this is the error that I am getting:

Stack dump:
0.      Program arguments: "C:\\Program Files\\LLVM\\bin\\clang++.exe" -cc1 -triple x86_64-pc-windows-msvc19.32.31332 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -fcoverage-compilation-dir=(ommited) -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\14.0.4" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\14.0.4\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.20348.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.20348.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.20348.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.20348.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.20348.0\\cppwinrt" --std=c++20 -fdeprecated-macro -fdebug-compilation-dir=(ommited) -ferror-limit 19 -fmessage-length=237 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.32.31332 -fdelayed-template-parsing -fmodules -fimplicit-module-maps -fmodules-cache-path=(ommited) "-fmodule-map-file=C:\\Program Files\\LLVM\\lib\\clang\\14.0.4\\include\\module.modulemap" -fmodules-validate-system-headers -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o ...AppData\\Local\\Temp\\main-573eef.o -x c++ code/main.cpp
1.      code/main.cpp:11:15: current parser token ';'
 #0 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x3b0d19c C:\Program Files\LLVM\bin\clang++.exe 0x3b0f3ea
 #1 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x3b0d7ee C:\Program Files\LLVM\bin\clang++.exe 0x25649b1
 #2 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x2575f5f C:\Program Files\LLVM\bin\clang++.exe 0x2604677
 #3 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x254ed1c C:\Program Files\LLVM\bin\clang++.exe 0x2604cdb
 #4 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x2575f6e C:\Program Files\LLVM\bin\clang++.exe 0x254a876
 #5 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x248d321 C:\Program Files\LLVM\bin\clang++.exe 0x248e848
 #6 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x32fc5f1 C:\Program Files\LLVM\bin\clang++.exe 0x30ab56a
 #7 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x30aa594 C:\Program Files\LLVM\bin\clang++.exe 0x30a5f0e
 #8 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x24bf902 C:\Program Files\LLVM\bin\clang++.exe 0x248a5ad
 #9 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x2520aee C:\Program Files\LLVM\bin\clang++.exe 0x6e25
#10 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x4344 C:\Program Files\LLVM\bin\clang++.exe 0x40ec
#11 0x00007ff606c6d19c C:\Program Files\LLVM\bin\clang++.exe 0x3f77fd8 (C:\Program Files\LLVM\bin\clang++.exe+0x3b0d19c)
#12 0x00007ff606c6d19c
#13 0x00007ff606c6d19c (C:\Program Files\LLVM\bin\clang++.exe+0x3b0d19c)
0x00007FF606C6D19C (0x000001F8E2E86840 0x0000000000000008 0x000001F8E2E87A60 0x0000009FC9D8B3B0)
0x00007FF606C6F3EA (0x000001F8E2E9B028 0x000019934CDCDA01 0x0000000000000000 0x0000000000000018)
0x00007FF606C6D7EE (0x000001F8E37D13A0 0x00007FF6055FBA24 0x0000009FC9D8B510 0x00007FF6056B538A)
0x00007FF6056C49B1 (0x000001F8E2E9B280 0x0000000000000000 0x0000000000000000 0x000001F8E2C11380)
0x00007FF6056D5F5F (0x000001F8E2E99818 0x00007FF60576566C 0x0000000000000560 0x00007FF606A8A688)
0x00007FF605764677 (0x000001F800000000 0x000001F8E5A94438 0x000001F8E2D83EE8 0x0000000000000001)
0x00007FF6056AED1C (0x00000000000ABF01 0x000001F8E2E989D0 0x0000000000000001 0x000001F8E2E989E8)
0x00007FF605764CDB (0x000001F8E4AF3A00 0x000001F8E4AF3440 0x000001F8E4AF3740 0x000001F8E4AF3D40)
0x00007FF6056D5F6E (0x0000009FC9D8D100 0x0000009FC9D8CE40 0x0000000000000018 0x000001F8E2D2BAD0)
0x00007FF6056AA876 (0x000001F8E2D71FF0 0x000019934CDCA97B 0x0000000000000000 0x0000000000000000)
0x00007FF6055ED321 (0x0000000000000000 0x000019934CDCBA0B 0x000001F8E2E58370 0x3163632D70697201)
0x00007FF6055EE848 (0x0000000000000001 0x00007FF606EC2B3C 0x0000009FC9D8D910 0x00007FF606EC2B13)
0x00007FF60645C5F1 (0x0000009FC9D8D918 0x0000000000000000 0x0000009FC9D8DA20 0x00007FF60505553B)
0x00007FF60620B56A (0x000001F8E2D9D9B0 0x000019934CDCB101 0x000001F8E53A5118 0x000019934CDCB1EB)
0x00007FF60620A594 (0x0000009FC9D8DB28 0x0000009FC9D8DB38 0x0000009FC9D8DB68 0x00007FF6055E862A)
0x00007FF606205F0E (0x0000000000000000 0x000019934CDCBFDB 0x2D646E756F72522D 0x3163632D70697274)
0x00007FF60561F902 (0x00000000000000E8 0x000001F8E2D0BB10 0x0000000000000018 0x000001F8E2D65B20)
0x00007FF6055EA5AD (0x0000009FC9D8E518 0x000001F800000000 0x000001F8E2D27FE0 0x000001F8E2D0BF00)
0x00007FF605680AEE (0x000000000000043C 0x000001F8E2CA0000 0x000001F8E2CA0000 0x00007FF886E6E2A9)
0x00007FF603166E25 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000)
0x00007FF603164344 (0x0000000000000153 0x000001F8E2CBF010 0x0000009FC9D8E8C0 0x000000039DCC6B43)
0x00007FF6031640EC (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000)
0x00007FF6070D7FD8 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000)
0x00007FF8853C7034 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), BaseThreadInitThunk() + 0x14 bytes(s)
0x00007FF886EA2651 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), RtlUserThreadStart() + 0x21 bytes(s)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 14.0.4
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
clang++: note: diagnostic msg: 
********************

Does someone already has addressed this issue? It's a know bug? There's some way to fix it? Probably bad compiler args?

Thanks in advice.

Upvotes: 1

Views: 673

Answers (1)

Aleksandr Medvedev
Aleksandr Medvedev

Reputation: 9008

At the time of writing this answer, it seems like modules are not yet supported by Clang. The table of C++20 features readiness says that it's only partially implemented in Clang15 (while the latest stable version is still 14):

C++20 Proposal Available in Clang?
P1103R3 Clang 15
P1766R1 (DR) Clang 11
P1811R0 No
P1703R1 Subsumed by P1857
P1874R1 Clang 15
P1979R0 No
P1779R3 Clang 15
P1857R3 No
P2115R0 Partial
P1815R2 Partial

Upvotes: 1

Related Questions