public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rsalmin2 at cc dot hut dot fi" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/32241]  New: Compiler segmentation fault when trying to call x.~X(); (X &x = f();) in a template
Date: Thu, 07 Jun 2007 10:30:00 -0000	[thread overview]
Message-ID: <bug-32241-14668@http.gcc.gnu.org/bugzilla/> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2638 bytes --]

/*

$ cat /proc/version
Linux version 2.6.20-15-generic (root@yellow) (gcc version 4.1.2 (Ubuntu
4.1.2-0ubuntu4)) #2 SMP Sun Apr 15 06:17:24 UTC 2007

$ gcc --version
gcc (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


$ g++ simplestack.cpp -o simplestack -g
simplestack.cpp: In member function ‘void SimpleStack<T, N>::pop() [with T =
int, long unsigned int N = 4ul]’:
simplestack.cpp:52:   instantiated from here
simplestack.cpp:32: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.

preprocessed source: http://cpp.sourceforge.net/?show=36942

 */


#include <stdexcept>
#include <memory>

template <typename T, std::size_t N>
class SimpleStack
{
        public:
                SimpleStack()
                        : ptr(reinterpret_cast<T*>(&buffer[0]))
                {
                }

                void push(const T& element)
                {
                        if(num >= N) throw std::out_of_range("stack full");
                        new (ptr + num) T(element);
                        ++num;
                }

                bool empty() const
                {
                        return num <= 0;
                }

                T& top()
                {
                        return *(ptr + num - 1);
                }

                void pop()
                {
                        top.~T(); // this is the line causing the error!
                        --num;
                }

        private:
                SimpleStack(const SimpleStack&);
                SimpleStack& operator=(const SimpleStack&);

                char buffer[N * sizeof(T)];
                T *ptr;
                std::size_t num;
};

#include <iostream>

int main()
{
        SimpleStack<int, 4> stack;
        stack.push(3);
        std::cout << stack.top() << std::endl;
        stack.pop();
}


-- 
           Summary: Compiler segmentation fault when trying to call x.~X();
                    (X &x = f();) in a template
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rsalmin2 at cc dot hut dot fi
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


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


             reply	other threads:[~2007-06-07 10:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-07 10:30 rsalmin2 at cc dot hut dot fi [this message]
2007-06-07 10:31 ` [Bug c++/32241] " rsalmin2 at cc dot hut dot fi
2007-06-08  0:03 ` fang at csl dot cornell dot edu
2007-06-08 10:16 ` rguenth at gcc dot gnu dot org
2007-06-09 22:20 ` [Bug c++/32241] [4.1/4.2/4.3 regression] ICE trying to call x.~X(); " reichelt at gcc dot gnu dot org
2007-06-29 18:41 ` mmitchel at gcc dot gnu dot org
2007-11-08 11:49 ` jakub at gcc dot gnu dot org
2007-11-10  7:36 ` jakub at gcc dot gnu dot org
2007-11-10  7:53 ` [Bug c++/32241] [4.1/4.2 " jakub at gcc dot gnu dot org
2008-07-04 22:14 ` [Bug c++/32241] [4.2 " jsm28 at gcc dot gnu dot org
2009-03-30 22:01 ` jsm28 at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-32241-14668@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).