Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++20][Modules] Includes in module partitions #60202

Open
SasisaDev opened this issue Jan 22, 2023 · 8 comments
Open

[C++20][Modules] Includes in module partitions #60202

SasisaDev opened this issue Jan 22, 2023 · 8 comments
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@SasisaDev
Copy link

SasisaDev commented Jan 22, 2023

module;

#include <cstdlib>

export module Types:Allocator;

export
template <typename ElementType>
class TAllocator {
public:
    static ElementType* Allocate(unsigned int sz) {
        return malloc(sz);
    }
};
export module Types;

export import :Allocator;
error: use of undeclared identifier 'malloc'; did you mean '_alloca'?
    return malloc(sz);
           ^~~~~~
           _alloca

If i move this implementation to main module, and not it's partition, code compiles.
If i use this code with other simmiliar modules, and they cross at some point, error becomes bigger.

In file included from D:\VisualStudio\VC\Tools\MSVC\14.34.31933\include\cstdlib:12:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\math.h:11:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:16:1: error: unknown type name '_UCRT_DISABLE_CLANG_WARNINGS'
_UCRT_DISABLE_CLANG_WARNINGS
^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:18:20: error: expected ';' after top level declarator
_CRT_BEGIN_C_HEADER
                   ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:175:26: error: unknown type name '_In_'
void __cdecl _fperrraise(_In_ int _Except);
                         ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:177:1: error: unknown type name '_Check_return_'
_Check_return_ _ACRTIMP short __cdecl _dclass(_In_ double _X);
^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:177:24: error: expected ';' after top level declarator
_Check_return_ _ACRTIMP short __cdecl _dclass(_In_ double _X);
                       ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:177:47: error: unknown type name '_In_'
_Check_return_ _ACRTIMP short __cdecl _dclass(_In_ double _X);
                                              ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:178:1: error: unknown type name '_Check_return_'
_Check_return_ _ACRTIMP short __cdecl _ldclass(_In_ long double _X);
^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:178:24: error: expected ';' after top level declarator
_Check_return_ _ACRTIMP short __cdecl _ldclass(_In_ long double _X);
                       ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:178:48: error: unknown type name '_In_'
_Check_return_ _ACRTIMP short __cdecl _ldclass(_In_ long double _X);
                                               ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:179:1: error: unknown type name '_Check_return_'
_Check_return_ _ACRTIMP short __cdecl _fdclass(_In_ float _X);
^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:179:24: error: expected ';' after top level declarator
_Check_return_ _ACRTIMP short __cdecl _fdclass(_In_ float _X);
                       ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:179:48: error: unknown type name '_In_'
_Check_return_ _ACRTIMP short __cdecl _fdclass(_In_ float _X);
                                               ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:181:1: error: unknown type name '_Check_return_'
_Check_return_ _ACRTIMP int __cdecl _dsign(_In_ double _X);
^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:181:24: error: expected ';' after top level declarator
_Check_return_ _ACRTIMP int __cdecl _dsign(_In_ double _X);
                       ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:181:44: error: unknown type name '_In_'
_Check_return_ _ACRTIMP int __cdecl _dsign(_In_ double _X);
                                           ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:182:1: error: unknown type name '_Check_return_'
_Check_return_ _ACRTIMP int __cdecl _ldsign(_In_ long double _X);
^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:182:24: error: expected ';' after top level declarator
_Check_return_ _ACRTIMP int __cdecl _ldsign(_In_ long double _X);
                       ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:182:45: error: unknown type name '_In_'
_Check_return_ _ACRTIMP int __cdecl _ldsign(_In_ long double _X);
                                            ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h:183:1: error: unknown type name '_Check_return_'
_Check_return_ _ACRTIMP int __cdecl _fdsign(_In_ float _X);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed new issue labels Jan 22, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 22, 2023

@llvm/issue-subscribers-clang-modules

@iains
Copy link
Contributor

iains commented Jan 22, 2023

export module Types;

export impot :Allocator;

........^ ......
there seems to be a typo there?

@SasisaDev
Copy link
Author

........^ ...... there seems to be a typo there?

It's my typo, cuz i rewrote this part manually here. In the code there's no typo, clang would've say me that i mistaken keyword.

@ChuanqiXu9
Copy link
Member

Weird, I can't reproduce this locally.

I tried the following two commands:

clang++ -std=c++20 Part.cppm --precompile -o Types-Allocator.pcm
clang++ -std=c++20 main.cppm -fprebuilt-module-path=. -fsyntax-only

And I am wondering if it is the problem of windows, then I tried:

clang++ -std=c++20 -Xclang -triple -Xclang x86_64-windows-msvc Part.cppm --precompile -o Types-Allocator.pcm
clang++ -std=c++20 -Xclang -triple -Xclang x86_64-windows-msvc main.cppm -fprebuilt-module-path=. -fsyntax-only

but things look fine still.

@ChuanqiXu9 ChuanqiXu9 assigned ChuanqiXu9 and unassigned ChuanqiXu9 Feb 24, 2023
@aaronmondal
Copy link
Member

aaronmondal commented Feb 28, 2023

I suspect this to be the same underlying issue as #58540.

@JarrodBegnoche
Copy link

JarrodBegnoche commented May 31, 2023

I'm having a similar issue when trying to include a header from opencv.

module;

#include <opencv2/core/types.hpp>

export module mod;

export cv::Scalar distance(cv::Scalar origin, cv::Scalar direction, double distance) {
    return origin + (direction * distance);
}
#include <format>
#include <iostream>

#include <opencv2/core/types.hpp>

import mod;

int main() {
    cv::Scalar origin(1.0, 2.0, 3.0, 1.0);
    cv::Scalar direction(2.0, 4.0, 5.0, 0.0);
    cv::Scalar sum = origin + direction;
    std::cout << std::format("Sum ({}, {}, {})", sum[0], sum[1], sum[2]) << std::endl;

    cv::Scalar end_point = distance(origin, direction, 2.0);
    std::cout << std::format("End Point ({}, {}, {})", end_point[0], end_point[1], end_point[2]) << std::endl;

    return 0;
}
$CXX -std=c++20 mod.cppm --precompile -I/usr/include/opencv4 -o mod.pcm
$CXX -std=c++20 main.cpp -I/usr/include/opencv4 -fprebuilt-module-path=. -fsyntax-only

The compilation will fail on the scalar addition:

main.cpp:11:29: error: invalid operands to binary expression ('cv::Scalar' (aka 'Scalar_<double>') and 'cv::Scalar')
    cv::Scalar sum = origin + direction;
                     ~~~~~~ ^ ~~~~~~~~~
/usr/include/opencv4/opencv2/core/types.hpp:1052:14: note: candidate template ignored: could not match 'Complex' against 'Scalar_'
Complex<_Tp> operator + (const Complex<_Tp>& a, const Complex<_Tp>& b)
             ^
/usr/include/opencv4/opencv2/core/types.hpp:1102:14: note: candidate template ignored: could not match 'Complex' against 'Scalar_'
Complex<_Tp> operator + (const Complex<_Tp>& a, _Tp b)
             ^
/usr/include/opencv4/opencv2/core/types.hpp:1112:14: note: candidate template ignored: could not match 'Complex' against 'Scalar_'
Complex<_Tp> operator + (_Tp b, const Complex<_Tp>& a)
             ^
/usr/include/opencv4/opencv2/core/types.hpp:1337:13: note: candidate template ignored: could not match 'Point_' against 'Scalar_'
Point_<_Tp> operator + (const Point_<_Tp>& a, const Point_<_Tp>& b)
            ^
/usr/include/opencv4/opencv2/core/types.hpp:1584:14: note: candidate template ignored: could not match 'Point3_' against 'Scalar_'
Point3_<_Tp> operator + (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
             ^
/usr/include/opencv4/opencv2/core/types.hpp:1759:12: note: candidate template ignored: could not match 'Size_' against 'Scalar_'
Size_<_Tp> operator + (const Size_<_Tp>& a, const Size_<_Tp>& b)
           ^
/usr/include/opencv4/opencv2/core/types.hpp:1964:12: note: candidate template ignored: could not match 'Rect_' against 'Scalar_'
Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Point_<_Tp>& b)
           ^
/usr/include/opencv4/opencv2/core/types.hpp:1976:12: note: candidate template ignored: could not match 'Rect_' against 'Scalar_'
Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Size_<_Tp>& b)
           ^
1 error generated.

This is reduced as much as I could. I originally ran into the issue when having multiple module partitions both include opencv and one imports the other. In the above example, if you move the opencv include to after import mod it will work but that isn't an option in module partitions.

$CXX --version
clang version 16.0.3
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/clang/latest/bin

@ChuanqiXu9
Copy link
Member

Is the operator static? I suspect this fall into #61807

@koplas
Copy link

koplas commented Jan 6, 2024

@SasisaDev I am unable to reproduce this on Windows MSVC clang 17 0d3eee3, it compiles for me without errors. Can you provide the preprocessor output and the command line flags you used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules
Projects
None yet
Development

No branches or pull requests

8 participants