llvm-project
llvm-project copied to clipboard
clang 13/14 + libstdc++-12: issue with getting base constructor from std::function
Hello, consider the following code: https://gcc.godbolt.org/z/xqczM3Gz3
It works fine with clang on libstdc++11, and with gcc 12 / libstdc++12.
However, with clang 13 and 14 + libstdc++12: the correct constructor isn't found ; it seems that unlike other paltform combos, the
template <
typename Fn,
std::enable_if_t<std::is_same_v<void, std::result_of_t<Fn(const int&)>>, int> = 0
>
effect(Fn&& fn)
: base_t{[fn = std::forward<Fn>(fn)](auto&& ctx) -> future {
fn(ctx);
return {};
}}
{}
takes precedence in this case.
foo.cpp:39:19: error: no viable conversion from '(lambda at foo.cpp:39:23)' to 'lager::effect'
lager::effect f = [ ] (auto&&) { return lager::future{}; };
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/bits/std_function.h:375:7: note: candidate inherited constructor not viable: no known conversion from '(lambda at foo.cpp:39:23)' to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument
function(nullptr_t) noexcept
^
foo.cpp:13:19: note: constructor from base class 'function<lager::future (const int &)>' inherited here
using base_t::base_t;
^
foo.cpp:16:5: note: candidate constructor not viable: no known conversion from '(lambda at foo.cpp:39:23)' to 'const lager::effect &' for 1st argument
effect(const effect&) = default;
^
foo.cpp:17:5: note: candidate constructor not viable: no known conversion from '(lambda at foo.cpp:39:23)' to 'lager::effect &&' for 1st argument
effect(effect&&) = default;
^
foo.cpp:25:5: note: candidate template ignored: requirement 'std::is_same_v<void, lager::future>' was not satisfied [with Fn = (lambda at foo.cpp:39:23)]
effect(Fn&& fn)
^
foo.cpp:39:23: note: candidate template ignored: could not match 'auto (*)(type-parameter-0-0 &&)' against 'lager::effect'
lager::effect f = [ ] (auto&&) { return lager::future{}; };
^
1 error generated.
@llvm/issue-subscribers-c-20
@llvm/issue-subscribers-clang-frontend
https://gcc.godbolt.org/z/zozbPYz63 Still seem to reproduce
Reduced:
class function {
public:
template <class F>
function(F&&) {}
};
struct effect : function {
using function::function;
template <
typename Fn,
typename Fn::type = 0
>
effect(Fn &&): function{0} {}
};
int main() {
::effect f = char{};
}
See https://compiler-explorer.com/z/TTE6166b1.
Output:
<source>:18:14: error: no viable conversion from 'char' to '::effect'
18 | ::effect f = char{};
| ^ ~~~~~~
<source>:7:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'char' to 'const effect &' for 1st argument
7 | struct effect : function {
| ^~~~~~
<source>:7:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'char' to 'effect &&' for 1st argument
7 | struct effect : function {
| ^~~~~~
<source>:14:5: note: candidate template ignored: substitution failure [with Fn = char]: type 'char' cannot be used prior to '::' because it has no members
12 | typename Fn::type = 0
| ~
13 | >
14 | effect(Fn &&): function{0} {}
| ^