This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/50681] New: A constexpr identifier in a header file generates undefined symbols in object code.
- From: "Fetrovsky at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 09 Oct 2011 18:29:01 +0000
- Subject: [Bug c++/50681] New: A constexpr identifier in a header file generates undefined symbols in object code.
- Auto-submitted: auto-generated
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'