-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Closed
Labels
clang:modulesC++20 modules and Clang Header ModulesC++20 modules and Clang Header Modules
Description
Clang version: 19.1.3
C++ version: 23
STL: from msvc
I was trying to compile nlohmann json using modules and I encountered an error (posting the original error for others who might google it):
C:\Users\username\.conan2\p\nlohm0567ffc90cfc1\p\include\nlohmann\detail\input\lexer.hpp:748:66: error: no matching constructor for initialization of 'std::initializer_list<char_int_type>' (aka 'initializer_list<int>')
748 | if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
I tried to reduce code to the minimum reproducible example and here's what I got (pay attention to the highlighted lines changing which kind of fixes the issue):
// main.cpp
import std; // Workaround 1: if I delete this line everything works fine
import mod;
int main() {
lexer{}.func({1,1});
return 0;
}
// mod.cppm
module;
#include "inc.hpp"
export module mod;
export using ::lexer;
export using ::adapter;
// inc.hpp
#pragma once
#include <initializer_list>
#include <string>
struct adapter {
using char_type = char;
};
template<typename InputAdapterType = adapter>
class lexer
{
using char_type = typename InputAdapterType::char_type; // Workaround 2: if I replace "InputAdapterType" here with "adapter" everything works fine
using char_int_type = typename std::char_traits<char_type>::int_type;
public:
void func(std::initializer_list<char_int_type> ranges) {}
};
// std.cppm module; #define _BUILD_STD_MODULE // Workaround 3: if I delete this line everything works fine #include <intrin.h> export module std; #include <initializer_list> #include <regex> // Workaround 4: if I delete this line everything works fine
The full error I get
C:/Users/username/CLionProjects/untitled23_1/std/modules/std.msvc.cppm:9:10: warning: '#include <filename>' attaches the declarations to the named module 'std', which is not usually intended; consider moving that directive before the module declaration [-Winclude-angled-in-module-purview]
9 | #include <initializer_list>
| ^
C:/Users/username/CLionProjects/untitled23_1/std/modules/std.msvc.cppm:7:15: warning: 'std' is a reserved name for a module [-Wreserved-module-identifier]
7 | export module std;
| ^
C:/Users/username/CLionProjects/untitled23_1/std/modules/std.msvc.cppm:10:10: warning: '#include <filename>' attaches the declarations to the named module 'std', which is not usually intended; consider moving that directive before the module declaration [-Winclude-angled-in-module-purview]
10 | #include <regex>
| ^
3 warnings generated.
[4/6] Building CXX object CMakeFiles/untitled23_1.dir/main.cpp.obj
FAILED: CMakeFiles/untitled23_1.dir/main.cpp.obj
C:\Tools\llvm\bin\clang++.exe -IC:/Users/username/CLionProjects/untitled23_1/include -IC:/Users/username/CLionProjects/untitled23_1/mod/../include -IC:/Users/username/CLionProjects/untitled23_1/std/include -O0 -std=c++23 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -g -Xclang -gcodeview -MD -MT CMakeFiles/untitled23_1.dir/main.cpp.obj -MF CMakeFiles\untitled23_1.dir\main.cpp.obj.d @CMakeFiles\untitled23_1.dir\main.cpp.obj.modmap -o CMakeFiles/untitled23_1.dir/main.cpp.obj -c C:/Users/username/CLionProjects/untitled23_1/main.cpp
C:/Users/username/CLionProjects/untitled23_1/main.cpp:6:18: error: no matching constructor for initialization of 'std::initializer_list<char_int_type>' (aka 'initializer_list<int>')
6 | lexer{}.func({1,1});
| ^~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\initializer_list:33:15: note: candidate constructor not viable: no known conversion from 'int' to 'const int *' for 1st argument
33 | constexpr initializer_list(const _Elem* _First_arg, const _Elem* _Last_arg) noexcept
| ^ ~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\initializer_list:21:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
21 | class initializer_list {
| ^~~~~~~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\initializer_list:21:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
21 | class initializer_list {
| ^~~~~~~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\initializer_list:31:15: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
31 | constexpr initializer_list() noexcept : _First(nullptr), _Last(nullptr) {}
| ^
C:\Users\username\CLionProjects\untitled23_1\mod\..\include\inc.hpp:17:52: note: passing argument to parameter 'ranges' here
17 | void func(std::initializer_list<char_int_type> ranges) {}
| ^
1 error generated.
Metadata
Metadata
Assignees
Labels
clang:modulesC++20 modules and Clang Header ModulesC++20 modules and Clang Header Modules