-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Closed
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issueDoes the clang frontend diverge from msvc on this issue
Description
#include <type_traits>
#include <variant>
using MyType = std::variant<double, int>;
template <typename T>
auto foo(T&& arg) -> std::remove_cvref_t<T>;
auto bar(MyType const& v) {
auto callable = []<typename Arg>(Arg&& arg) -> MyType {
return foo(std::forward<Arg>(arg));
};
return std::visit(callable, v);
}
template <typename T>
auto foo(T&& arg) -> std::remove_cvref_t<T> {
return arg;
}
int main() {
MyType b {5.3};
bar(b);
}
https://godbolt.org/z/n54f19hn5
It seems that only the declarations get generated for foo
, but no definitions. However, if foo
is no longer forward declared, everything works: https://godbolt.org/z/c1WY647af.
Diagnostics:
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-c83671.o: in function `std::variant<double, int> bar(std::variant<double, int> const&)::$_0::operator()<double const&>(double const&) const':
<source>:11:(.text+0x315): undefined reference to `std::remove_cvref<double const&>::type foo<double const&>(double const&)'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-c83671.o: in function `std::variant<double, int> bar(std::variant<double, int> const&)::$_0::operator()<int const&>(int const&) const':
<source>:11:(.text+0x3f5): undefined reference to `std::remove_cvref<int const&>::type foo<int const&>(int const&)'
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issueDoes the clang frontend diverge from msvc on this issue