public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50681] New: A constexpr identifier in a header file generates undefined symbols in object code.
@ 2011-10-09 18:29 Fetrovsky at gmail dot com
  2011-10-09 18:32 ` [Bug c++/50681] " Fetrovsky at gmail dot com
  2011-10-09 18:38 ` [Bug c++/50681] [C++0x] " paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: Fetrovsky at gmail dot com @ 2011-10-09 18:29 UTC (permalink / raw)
  To: gcc-bugs

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'


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/50681] A constexpr identifier in a header file generates undefined symbols in object code.
  2011-10-09 18:29 [Bug c++/50681] New: A constexpr identifier in a header file generates undefined symbols in object code Fetrovsky at gmail dot com
@ 2011-10-09 18:32 ` Fetrovsky at gmail dot com
  2011-10-09 18:38 ` [Bug c++/50681] [C++0x] " paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: Fetrovsky at gmail dot com @ 2011-10-09 18:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50681

Feto <Fetrovsky at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://ideone.com/kfs6n
                 CC|                            |Fetrovsky at gmail dot com
           Severity|normal                      |major


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/50681] [C++0x] A constexpr identifier in a header file generates undefined symbols in object code.
  2011-10-09 18:29 [Bug c++/50681] New: A constexpr identifier in a header file generates undefined symbols in object code Fetrovsky at gmail dot com
  2011-10-09 18:32 ` [Bug c++/50681] " Fetrovsky at gmail dot com
@ 2011-10-09 18:38 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-09 18:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50681

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID
            Summary|A constexpr identifier in a |[C++0x] A constexpr
                   |header file generates       |identifier in a header file
                   |undefined symbols in object |generates undefined symbols
                   |code.                       |in object code.

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-09 18:37:56 UTC ---
Yes, you still need a definition, constexpr or not.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-10-09 18:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-09 18:29 [Bug c++/50681] New: A constexpr identifier in a header file generates undefined symbols in object code Fetrovsky at gmail dot com
2011-10-09 18:32 ` [Bug c++/50681] " Fetrovsky at gmail dot com
2011-10-09 18:38 ` [Bug c++/50681] [C++0x] " paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).