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 to int 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 from foo_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
Hi!
NB:
Here is a sample project, depicting the problem: https://godbolt.org/z/neo8M8orM
Imagine, that I have a
static inlinefunctionfoo_header, defined in some header:And this function is used in a template function
foo_modulein some module:Now I want to use latter in my
main.cpp:However, clang falsely claims, that there is no matching function
foo_header:Here are some observation, based on which, I make an assumption that this is a clang bug:
Ttointlike this:staticfromfoo_headerfunction declarationBased on those observations, I could assume that body of
foo_moduletemplate function gets compiled in different translation unit, from where header was included, and thereforestaticspecifier onfoo_headerhides this function