https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105908
Bug ID: 105908
Summary: out-of-class definition of templated method with
decltype in trailing return type fails to compile
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: falemagn at gmail dot com
Target Milestone: ---
This code fails to compile with g++12.
struct test
{
template <typename T>
int templated_func();
int normal_func();
template <typename T>
auto call_with_scope_templated_func() ->
decltype(test::templated_func<T>());
template <typename T>
auto call_templated_func() -> decltype(templated_func<T>());
template <typename T>
auto call_normal_func() -> decltype(normal_func());
};
template <typename T>
auto test::call_with_scope_templated_func() ->
decltype(test::templated_func<T>())
{
return templated_func<T>();
}
template <typename T>
auto test::call_templated_func() -> decltype(templated_func<T>())
{
return templated_func<T>();
}
template <typename T>
auto test::call_normal_func() -> decltype(normal_func())
{
return normal_func();
}
gcc complaines like this:
<source>:25:6: error: no declaration matches 'decltype
(((test*)this)->templated_func<T>()) test::call_templated_func()'
25 | auto test::call_templated_func() -> decltype(templated_func<T>())
| ^~~~
<source>:12:10: note: candidate is: 'template<class T> decltype
(((test*)this)->templated_func<T>()) test::call_templated_func()'
12 | auto call_templated_func() -> decltype(templated_func<T>());
| ^~~~~~~~~~~~~~~~~~~
<source>:1:8: note: 'struct test' defined here
1 | struct test
| ^~~~
However, as you can see, it works if the class name is prepended to the
template_func<T>() call within the decltype expression, and it also works if
the called function is not templated.
G++11 doesn't show any such issue, nor does clang.
An working example on godbolt: https://godbolt.org/z/xK5aoxfxY