I have a small templated struct that forwards a call to another templated struct. It should be simple. But I am facing a problem. The idea is that One struct uses the template parameter to forward a call depending on a compile time constant passed as parameter.
Here is the minimal code I manage to have to reproduce the problem:
struct OutFoo
{
template <bool Condition>
static constexpr void foo_ce() noexcept
{
}
static constexpr void foo() noexcept
{
}
};
template <typename OF>
struct InnerFoo
{
template <bool b>
static constexpr void inner_foo() noexcept
{
// OF::foo_ce<b>(); // Does not compile
// OF::foo_ce<true>(); // Does not compile
OF::foo();
}
};
int main()
{
InnerFoo<OutFoo>::inner_foo<true>();
}
My understanding is that both lines commented out should compile, given that OF (aka OutFoo should be taken and then foo_ce() should be called.
This actually works with MSVC but not with gcc. Who is right? What am I doing wrong?
gcc error:
source>: In static member function 'static constexpr void InnerFoo<OF>::inner_foo()':
<source>:22:19: error: expected primary-expression before ')' token
22 | OF::foo_ce<b>();
| ^
<source>:23:22: error: expected primary-expression before ')' token
23 | OF::foo_ce<true>();
| ^
<source>: In instantiation of 'static constexpr void InnerFoo<OF>::inner_foo() [with bool b = true; OF = OutFoo]':
<source>:30:39: required from here
<source>:22:15: error: invalid operands of types '<unresolved overloaded function type>' and 'bool' to binary 'operator<'
22 | OF::foo_ce<b>();
| ~~~~~~^~
<source>:23:15: error: invalid operands of types '<unresolved overloaded function type>' and 'bool' to binary 'operator<'
23 | OF::foo_ce<true>();
| ~~~~~~^~~~~
clang error is more clear:
<source>:22:9: error: missing 'template' keyword prior to dependent template name 'foo_ce'
OF::foo_ce<b>();
^ ~~~
<source>:23:9: error: missing 'template' keyword prior to dependent template name 'foo_ce'
OF::foo_ce<true>();
^ ~~~~~~
2 errors generated.