Open
Description
Hello. LLVM.
I encountered an incomprehensible compilation error related to a static template function while using C++ modules.
I provide the minimal code below to reproduce the issue.
It's my first bug report to LLVM. Please let me know if there's anything wrong.
Environment
Ubuntu clang version 21.0.0 (++20250305083430+f4878cb91612-1exp120250305083603.767)
Target: x86_64-pc-linux-gnu
Codes
// main.cpp
#include "dummy_cuda_runtime.h"
#include <cstdint>
import MyModule;
int main() {
uint16_t *buffer;
cudaMalloc(&buffer, 100 * sizeof(uint16_t)); // No Compile Error
MyClass aaa;
cudaMalloc(&buffer, 100 * sizeof(uint16_t)); // Compile Error
}
// a.cppm
module;
#include "dummy_cuda_runtime.h"
#include <cstdint>
export module MyModule;
export class MyClass {
public:
MyClass() {
// If below line is not in constructor, No Compile Error
cudaMalloc(&buffer_, 100 * sizeof(uint16_t));
}
uint16_t *buffer_;
};
// dummy_cuda_runtime.h
template <class T> static void cudaMalloc(T **devPtr, int size) {
// dummy
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.30)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
project(modules-example)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
add_executable(demo main.cpp)
target_sources(demo PUBLIC FILE_SET all_my_modules TYPE CXX_MODULES FILES
a.cppm)
mkdir build
cd build
cmake .. -G Ninja
ninja
FAILED: CMakeFiles/demo.dir/main.cpp.o
/usr/lib/llvm-21/bin/clang++ -std=gnu++20 -MD -MT CMakeFiles/demo.dir/main.cpp.o -MF CMakeFiles/demo.dir/main.cpp.o.d @CMakeFiles/demo.dir/main.cpp.o.modmap -o CMakeFiles/demo.dir/main.cpp.o -c /home/jae/Projects/cpp_modules3/main.cpp
/home/jae/Projects/cpp_modules3/main.cpp:15:5: error: no matching function for call to 'cudaMalloc'
15 | cudaMalloc(&buffer, 100 * sizeof(uint16_t)); // Compile Error
| ^~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.