All compiled using -std=c++2a.
-------------------------
First - defining a constexpr member function of a template after use.
template <typename tTYPE>
struct SFoo
{
constexpr void foo();
};
int main()
{
SFoo<int> foo;
foo.foo();
}
template <typename tTYPE>
constexpr void SFoo<tTYPE>::foo()
{}
GCC compiles and links this fine. Clang doesn't instantiate foo(), and thus fails to link.
Quote4:18: warning: inline function 'SFoo<int>::foo' is not defined [-Wundefined-inline]
NOTE: constexpr implies inline.
I think LLVM is wrong here - the definition just needs to be provided somewhere. Am I right?
Quote
The exact quote from n3290 § 7.1.2.4 is:
An inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case (3.2). [ Note: A call to the inline function may be encountered before its definition appears in the translation unit. —end note ]
(From this post).
-------------------------------------
Second, default initialization of unused constexpr template value.
template <typename T>
constexpr int n;
int main()
{}
Again, GCC accepts it, but clang++ complains:
Quote2:15: error: default initialization of an object of const type 'const int'
If you want to only use specializations of n, requiring a value here is unnecessary (and could prevent detecting bugs at compile-time).
--------------------------------------
Are both of these LLVM bugs?