https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65719
Bug ID: 65719
Summary: Link error with constexpr variable template
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ldionne.2 at gmail dot com
The following code triggers a link error on GCC trunk:
------------------------------------------------------------------------------
struct FunctionObject {
void operator()() const { }
};
template <typename T>
constexpr FunctionObject f{};
// template FunctionObject f<int>;
int main() {
f<int>();
}
------------------------------------------------------------------------------
Curiously, uncommenting the explicit instantiation of f fixes the problem.
Similarly, making the variable template non-constexpr fixes the problem too.
My version of GCC:
› ~/code/gcc5/bin/g++ --version
g++ (GCC) 5.0.0 20150409 (experimental)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The exact output:
› ~/code/gcc5/bin/g++ -std=c++1y ~/code/hana/test/worksheet.cpp
Undefined symbols for architecture x86_64:
"f<int>", referenced from:
_main in cc7xJZsT.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status