This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/50681] New: A constexpr identifier in a header file generates undefined symbols in object code.


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'


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]