Consider following code:
template <typename T> struct X
{
X(T) {}
void foo() {}
};
template <typename T> struct Y
{
int object = 0;
void bar()
{
X(object).foo();
}
};
GCC 8.2 compiles it, while Clang 7 spits out following error:
<source>:13:18: error: member reference base type 'X' is not a structure or union X(object).foo(); ~~~~~~~~~^~~~
This looks like a bug to me.
The conditions are very specific: If either structure is not a template, or if object
is not a member variable, or if CTAD (class template argument deduction) is not involved, then Clang compiles the code as well.
What's going on here? Is it indeed a Clang bug?
And what's more important, how can I make the code compile with minimal changes, preferrably without getting rid of CTAD?
The only flag used is -std=c++17
.
clang++ --version
is
clang version 7.0.0 (tags/RELEASE_700/final 342594) Target: x86_64-unknown-linux-gnu Thread model: posix