public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57588] New: [C++11][constexpr] static constexpr in class fails to link
@ 2013-06-11 16:29 mattyclarkson at gmail dot com
  2013-06-11 16:55 ` [Bug c++/57588] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: mattyclarkson at gmail dot com @ 2013-06-11 16:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57588
           Summary: [C++11][constexpr] static constexpr in class fails to
                    link
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mattyclarkson at gmail dot com

The following code, links in optimisation modes but not others:

  #include <iostream>

 
///////////////////////////////////////////////////////////////////////////////
  class Literal {
  private:
    Literal() = delete;
    Literal(const Literal&) = delete;
    Literal(Literal&&) = delete;
    Literal& operator=(const Literal&) = delete;
    Literal& operator=(Literal&&) = delete;
    ~Literal() = default;

  public:
    constexpr Literal(const int i);

  public:
    constexpr operator int() const;

  private:
    int int_;
  };

  constexpr Literal::Literal(const int i) : int_(i) {};

  constexpr Literal::operator int() const {
    return int_;
  }

 
///////////////////////////////////////////////////////////////////////////////
  class Test {
  private:
    Test(const Test&) = delete;
    Test(Test&&) = delete;
    Test& operator=(const Test&) = delete;
    Test& operator=(Test&&) = delete;
    ~Test() = default;

  public:
    static constexpr const Literal kLiteral = Literal(99);

  public:
    constexpr Test();

  public:
    constexpr operator int() const;

  private:
    int int_;
  };

  constexpr Test::Test() : int_(kLiteral) {};

  constexpr Test::operator int() const {
    return int_;
  }

 
///////////////////////////////////////////////////////////////////////////////
  int main() {
    std::cout << Literal(15) << std::endl;
    std::cout << Test() << std::endl;
    return 0;
  }

Has some odd compilation on my machine:

  [matt test] uname -a
  Linux office.acer-m5810 3.8.13-100.fc17.x86_64 #1 SMP Mon May 13 13:36:17 UTC
2013 x86_64 x86_64 x86_64 GNU/Linux
  [matt test] g++ -std=c++11 test.cpp -o test -O0 -g && ./test
  /tmp/ccZtV9ku.o: In function `Test::Test()':
  /home/matt/test/test.cpp:51: undefined reference to `Test::kLiteral'
  collect2: error: ld returned 1 exit status
  [matt test] g++ -std=c++11 test.cpp -o test -O1 -g && ./test
  15
  99
  [matt test] g++ -std=c++11 test.cpp -o test -O2 -g && ./test
  15
  99
  [matt test] g++ -std=c++11 test.cpp -o test -O3 -g && ./test
  15
  99

However, on gcc.godbolt.org and ideone.com I cannot get the same compilation
error with 4.7.2.  I'm assuming I'm not being a donkey and doing something
against the standard? :/

If I can help with any debugging, please ask.


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

end of thread, other threads:[~2015-03-25 16:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-11 16:29 [Bug c++/57588] New: [C++11][constexpr] static constexpr in class fails to link mattyclarkson at gmail dot com
2013-06-11 16:55 ` [Bug c++/57588] " redi at gcc dot gnu.org
2013-06-11 16:59 ` redi at gcc dot gnu.org
2013-06-11 18:08 ` mattyclarkson at gmail dot com
2013-06-12  9:57 ` daniel.kruegler at googlemail dot com
2013-06-12 10:02 ` daniel.kruegler at googlemail dot com
2013-06-12 10:42 ` redi at gcc dot gnu.org
2013-07-01  6:20 ` [Bug c++/57588] [C++11] " richard-gccbugzilla at metafoo dot co.uk
2015-03-25 16:40 ` 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).