public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32241]  New: Compiler segmentation fault when trying to call x.~X(); (X &x = f();) in a template
@ 2007-06-07 10:30 rsalmin2 at cc dot hut dot fi
  2007-06-07 10:31 ` [Bug c++/32241] " rsalmin2 at cc dot hut dot fi
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: rsalmin2 at cc dot hut dot fi @ 2007-06-07 10:30 UTC (permalink / raw)
  To: gcc-bugs

[-- 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


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

end of thread, other threads:[~2009-03-30 22:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-07 10:30 [Bug c++/32241] New: Compiler segmentation fault when trying to call x.~X(); (X &x = f();) in a template rsalmin2 at cc dot hut dot fi
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

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