Open
Description
Hi!
NB:
Here is a sample project, depicting the problem: https://godbolt.org/z/neo8M8orM
Imagine, that I have a static inline
function foo_header
, defined in some header:
// header.hpp
#pragma once
static inline int foo_header(int x) {
return x;
}
And this function is used in a template function foo_module
in some module:
// module.cpp
module;
#include "header.hpp"
export module Mod;
export template<typename T>
T foo_module(T x) {
return foo_header(x);
}
Now I want to use latter in my main.cpp
:
// main.cpp
import Mod;
int main() {
int x = foo_module(5);
return 0;
}
However, clang falsely claims, that there is no matching function foo_header
:
In file included from /app/main.cpp:1:
module.cpp:9:12: error: no matching function for call to 'foo_header'
9 | return foo_header(x);
| ^~~~~~~~~~
main.cpp:4:13: note: in instantiation of function template specialization 'foo_module<int>' requested here
4 | int x = foo_module(5);
| ^
1 error generated.
Here are some observation, based on which, I make an assumption that this is a clang bug:
- This code compiles/works properly on trunk of gcc
- This code compiles/works properly if I explicitly cast template parameter
T
toint
like this:
// module.cpp
export template<typename T>
T foo_module(T x) {
return foo_header(static_cast<int>(x));
}
- This code compiles/works properly if I remove keyword
static
fromfoo_header
function declaration
Based on those observations, I could assume that body of foo_module
template function gets compiled in different translation unit, from where header was included, and therefore static
specifier on foo_header
hides this function