[Bug c++/50681] New: A constexpr identifier in a header file generates undefined symbols in object code.
Fetrovsky at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Oct 9 18:29:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50681
Bug #: 50681
Summary: A constexpr identifier in a header file generates
undefined symbols in object code.
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: Fetrovsky@gmail.com
kMaxValue in class template Cursor generates an undefined symbol in the object
code. Since the value isn't defined anywhere else, I get an undefined symbol
error from the linker.
template<typename Type = int>
class Cursor {
public:
typedef std::pair<Type, Type> Pair;
private:
Pair _position;
public:
static Type constexpr kMaxValue =
std::numeric_limits<Type>::max();
Cursor(Pair const& size = Pair(kMaxValue, kMaxValue)):
_position(size.first, size.first) {}
};
Example usage:
class UI {
private:
Cursor<> _cursor;
public:
virtual Cursor<>::Pair GetSize() {
return make_pair(0, 0);
}
};
int main() {
return UI().GetSize().first;
}
Linker message:
x.cpp:(.text._ZN2UIC2Ev[_ZN2UIC5Ev]+0x1c): undefined reference to
`Cursor<int>::kMaxValue'
x.cpp:(.text._ZN2UIC2Ev[_ZN2UIC5Ev]+0x21): undefined reference to
`Cursor<int>::kMaxValue'
More information about the Gcc-bugs
mailing list