public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66656] New: static constexpr array member: cannot get size via constexpr function
@ 2015-06-24 19:02 g5834847 at trbvm dot com
  2015-06-25  9:46 ` [Bug c++/66656] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: g5834847 at trbvm dot com @ 2015-06-24 19:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66656

            Bug ID: 66656
           Summary: static constexpr array member: cannot get size via
                    constexpr function
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: g5834847 at trbvm dot com
  Target Milestone: ---

////////////////////////////////////////

#include <iostream>

template <typename T, size_t N>
constexpr size_t array_size(const T (&)[N])
{
  return N;
}

class X {
public:
  struct item {
    char const* const name;
    int               price;
  };

  static const     item arr0[2];
  static constexpr item arr1[3] = {{"asdf", 0}, {"qwer", 1}, {"zxcv", 2}};

  static size_t constexpr size0() {
    return array_size(arr0);    // perfect
  }

  static size_t constexpr size1() {
    return array_size(arr1);    // problem!!
  }

};

const X::item X::arr0[] = {{"asdf", 0}, {"qwer", 1}};

int main()
{
  X x;
  std::cout << x.size0() << std::endl; // perfect
  std::cout << x.size1() << std::endl; // ERROR IN THIS LINE (cannot link!??)
  return 0;
}
////////////////////////////////////////////



$ c++ -std=c++14 -o go go.cpp

/tmp/ccPGS4ZN.o: In function `X::size1()':
go.cpp:(.text._ZN1X5size1Ev[_ZN1X5size1Ev]+0x5): undefined reference to
`X::arr1'
collect2: error: ld returned 1 exit status


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

* [Bug c++/66656] static constexpr array member: cannot get size via constexpr function
  2015-06-24 19:02 [Bug c++/66656] New: static constexpr array member: cannot get size via constexpr function g5834847 at trbvm dot com
@ 2015-06-25  9:46 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2015-06-25  9:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66656

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
https://gcc.gnu.org/wiki/VerboseDiagnostics#missing_static_const_definition


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

end of thread, other threads:[~2015-06-25  9:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-24 19:02 [Bug c++/66656] New: static constexpr array member: cannot get size via constexpr function g5834847 at trbvm dot com
2015-06-25  9:46 ` [Bug c++/66656] " redi at gcc dot gnu.org

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).