Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!sirius.trl.oz.au!addie From: addie@sirius.trl.oz.au (Ron Addie) Newsgroups: gnu.g++.bug Subject: g++ bug (part 1) Message-ID: <8905010646.AA02976@orion.trl.oz> Date: 1 May 89 21:46:55 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 729 # To unbundle files into distribution package, on a Unix machine, # go to the appropriate directory and sh this file echo bug-report 1>&2 cat >bug-report <<'End of bug-report' We have recently installed gnu c++ version 1.27. I have found that one of my programs whichs works with the AT&T c++ compiler on a vax doesn't work with g++ on our Sun 3. The Sun is operating under Sun OS 4.0, with some of the patches which upgrade to 4.0.1 installed, but not all. Also, test 13 (from the 1.25 distribution) does not run successfully. Here is an example of compilation and running of this test: argo:~/g++>g++ -o test13 test13.cc intSLList.cc intDLList.cc argo:~/g++>test13 intSLList a: length() = 0 prepending...90 75 84 81 74 99 52 85 86 47 a: length() = 10 47 86 85 52 99 74 81 84 75 90 appending...8 21 66 51 88 21 66 19 52 29 a: length() = 20 47 86 85 52 99 74 81 84 75 90 8 21 66 51 88 21 66 19 52 29 b = a: length() = 20 47 86 85 52 99 74 81 84 75 90 8 21 66 51 88 21 66 19 52 29 remove_front of first 10 elements: 47 86 85 52 99 74 81 84 75 90 b: length() = 10 8 21 66 51 88 21 66 19 52 29 inserting after sixth element...22 b: length() = 11 8 21 66 51 88 21 22 66 19 52 29 after b.clear() b: length() = 0 Segmentation fault (core dumped) argo:~/g++> Here is the details concerning the files md and tm.h which you requested in the bug report guidelines argo:/home2/users/liu/gnu/gcc>ls -l md lrwxrwxrwx 1 liu 7 Apr 24 11:17 md -> m68k.md argo:/home2/users/liu/gnu/gcc>ls -l tm.h lrwxrwxrwx 1 liu 9 Apr 24 11:16 tm.h -> tm-sun3.h Here is the result of running the test with the "-g" option: argo:~/g++>g++ -g -o test13 *.cc argo:~/g++>test13 intSLList a: length() = 0 prepending...90 75 84 81 74 99 52 85 86 47 a: length() = 10 47 86 85 52 99 74 81 84 75 90 appending...8 21 66 51 88 21 66 19 52 29 a: length() = 20 47 86 85 52 99 74 81 84 75 90 8 21 66 51 88 21 66 19 52 29 b = a: length() = 20 47 86 85 52 99 74 81 84 75 90 8 21 66 51 88 21 66 19 52 29 remove_front of first 10 elements: 47 86 85 52 99 74 81 84 75 90 b: length() = 10 8 21 66 51 88 21 66 19 52 29 inserting after sixth element...22 b: length() = 11 8 21 66 51 88 21 22 66 19 52 29 after b.clear() b: length() = 0 Segmentation fault (core dumped) [Seems to be exactly the same] I have included the source for test13 in this message. (in another file) Ron Addie Telecom Australia Research Laboratories. End of bug-report echo intDLList.cc 1>&2 cat >intDLList.cc <<'End of intDLList.cc' // This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) This file is part of GNU CC. GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the GNU CC General Public License for full details. Everyone is granted permission to copy, modify and redistribute GNU CC, but only under the conditions described in the GNU CC General Public License. A copy of this license is supposed to have been given to you along with GNU CC so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. */ #include #include "intDLList.h" // error handling void default_intDLList_error_handler(char* msg) { cerr << "Fatal intDLList error. " << msg << "\n"; exit(1); } one_arg_error_handler_t intDLList_error_handler = default_intDLList_error_handler; one_arg_error_handler_t set_intDLList_error_handler(one_arg_error_handler_t f) { one_arg_error_handler_t old = intDLList_error_handler; intDLList_error_handler = f; return old; } void intDLList::error(const char* msg) { (*intDLList_error_handler)(msg); } intDLList::intDLList(intDLList& a) { if (a.h == 0) h = 0; else { intDLListNode* p = a.h; intDLListNode* t = new intDLListNode(p->hd); h = t; p = p->fd; while (p != a.h) { intDLListNode* n = new intDLListNode(p->hd); t->fd = n; n->bk = t; t = n; p = p->fd; } t->fd = h; h->bk = t; return; } } inline intDLList& intDLList::operator = (intDLList& a) { if (h != a.h) { clear(); if (a.h != 0) { intDLListNode* p = a.h; intDLListNode* t = new intDLListNode(p->hd); h = t; p = p->fd; while (p != a.h) { intDLListNode* n = new intDLListNode(p->hd); t->fd = n; n->bk = t; t = n; p = p->fd; } t->fd = h; h->bk = t; } } return *this; } void intDLList::clear() { if (h == 0) return; intDLListNode* p = h->fd; h->fd = 0; h = 0; while (p != 0) { intDLListNode* nxt = p->fd; delete(p); p = nxt; } } void intDLList::prepend(int item) { intDLListNode* t = new intDLListNode(item); if (h == 0) t->fd = t->bk = h = t; else { t->fd = h->fd; t->bk = h; h->fd = t; h = t; } } void intDLList::append(int item) { intDLListNode* t = new intDLListNode(item); if (h == 0) t->fd = t->bk = h = t; else { t->fd = h; t->bk = h->bk; h->bk->fd = t; h->bk = t; } } void intDLListTrav::insert_after(int item) { if (current == 0) { L->error("insert_after: null traverser"); return; } intDLListNode* t = new intDLListNode(item, current, current->fd); current->fd->bk = t; current->fd = t; } void intDLListTrav::insert_before(int item) { if (current == 0) { L->error("insert_before: null traverser"); return; } intDLListNode* t = new intDLListNode(item, current->bk, current); current->bk->fd = t; current->bk = t; if (current == L->h) L->h = t; } void intDLListTrav::del(int dir = 1) { if (current == 0) { L->error("del: null traverser"); return; } intDLListNode* t = current; if (t->fd == t) current = L->h = 0; else { if (dir < 0) { if (t == L->h) current == 0; else current = t->bk; } else { if (t == L->h->bk) current = 0; else current = t->fd; } t->bk->fd = t->fd; t->fd->bk = t->bk; if (t == L->h) L->h = t->fd; } delete t; } int intDLList::remove_front() { if (h == 0) error("remove_front of empty list"); intDLListNode* t = h; int res = t->hd; if (h->fd == h) h = 0; else { h->fd->bk = h->bk; h->bk->fd = h->fd; h = h->fd; } delete t; return res; } void intDLList::del_front() { if (h == 0) error("del_front of empty list"); intDLListNode* t = h; if (h->fd == h) h = 0; else { h->fd->bk = h->bk; h->bk->fd = h->fd; h = h->fd; } delete t; } int intDLList::remove_rear() { if (h == 0) error("remove_rear of empty list"); intDLListNode* t = h->bk; int res = t->hd; if (h->fd == h) h = 0; else { t->fd->bk = t->bk; t->bk->fd = t->fd; } delete t; return res; } void intDLList::del_rear() { if (h == 0) error("del_rear of empty list"); intDLListNode* t = h->bk; if (h->fd == h) h = 0; else { t->fd->bk = t->bk; t->bk->fd = t->fd; } delete t; } End of intDLList.cc echo intSLList.cc 1>&2 cat >intSLList.cc <<'End of intSLList.cc' // This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) This file is part of GNU CC. GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the GNU CC General Public License for full details. Everyone is granted permission to copy, modify and redistribute GNU CC, but only under the conditions described in the GNU CC General Public License. A copy of this license is supposed to have been given to you along with GNU CC so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. */ #include #include "intSLList.h" // error handling void default_intSLList_error_handler(char* msg) { cerr << "Fatal intSLList error. " << msg << "\n"; exit(1); } one_arg_error_handler_t intSLList_error_handler = default_intSLList_error_handler; one_arg_error_handler_t set_intSLList_error_handler(one_arg_error_handler_t f) { one_arg_error_handler_t old = intSLList_error_handler; intSLList_error_handler = f; return old; } void intSLList::error(const char* msg) { (*intSLList_error_handler)(msg); } intSLList::intSLList(intSLList& a) { if (a.last == 0) last = 0; else { intSLListNode* p = a.last->tl; intSLListNode* h = new intSLListNode(p->hd); last = h; p = p->tl; for (;;) { intSLListNode* n = new intSLListNode(p->hd); last->tl = n; last = n; if (p == a.last) { last->tl = h; return; } else p = p->tl; } } } inline intSLList& intSLList::operator = (intSLList& a) { if (last == a.last) return *this; else { clear(); if (a.last != 0) { intSLListNode* p = a.last->tl; intSLListNode* h = new intSLListNode(p->hd); last = h; p = p->tl; for (;;) { intSLListNode* n = new intSLListNode(p->hd); last->tl = n; last = n; if (p == a.last) { last->tl = h; return *this; } else p = p->tl; } } } } void intSLList::clear() { if (last == 0) return; intSLListNode* p = last->tl; last->tl = 0; last = 0; while (p != 0) { intSLListNode* nxt = p->tl; delete(p); p = nxt; } } void intSLList::prepend(int item) { intSLListNode* t = new intSLListNode(item); if (last == 0) t->tl = last = t; else { t->tl = last->tl; last->tl = t; } } void intSLList::append(int item) { intSLListNode* t = new intSLListNode(item); if (last == 0) t->tl = last = t; else { t->tl = last->tl; last = last->tl = t; } } void intSLListTrav::insert_after(int item) { intSLListNode* t = new intSLListNode(item); if (L->last == 0) t->tl = L->last = current = t; else if (current == 0) { t->tl = L->last->tl; L->last = t; } else if (L->last == current) { t->tl = current->tl; current->tl = L->last = t; } else { t->tl = current->tl; current->tl = t; } } int intSLList::remove_front() { if (last == 0) error("remove_front of empty list"); intSLListNode* t = last->tl; int res = t->hd; if (t == last) last = 0; else last->tl = t->tl; delete t; return res; } int intSLList::remove_front(int& x) { if (last == 0) return 0; else { intSLListNode* t = last->tl; x = t->hd; if (t == last) last = 0; else last->tl = t->tl; delete t; return 1; } } void intSLList::del_front() { if (last == 0) error("del_front of empty list"); intSLListNode* t = last->tl; if (t == last) last = 0; else last->tl = t->tl; delete t; } End of intSLList.cc echo test13.cc 1>&2 cat >test13.cc <<'End of test13.cc' /* test/demo of linked structures */ #include #include "intSLList.h" #include "intDLList.h" void printint(int x) { cout << x << " "; } void printlist(intSLList& l) { for (intSLListTrav p(l); p; p.advance()) cout << p.get() << " "; cout << "\n"; } void printDlist(intDLList& l) { for (intDLListTrav p(l); p; p.advance()) cout << p.get() << " "; cout << "\n"; } main() { int i, x; intSLList a; cout << "intSLList a: length() = " << a.length() << "\n"; printlist(a); cout << "prepending..."; for (i = 0; i < 10; ++i) { x = rand() % 100; cout << x << " "; a.prepend(x); } cout << "\n"; cout << "a: length() = " << a.length() << "\n"; printlist(a); cout << "appending..."; for (i = 0; i < 10; ++i) { x = rand() % 100; cout << x << " "; a.append(x); } cout << "\n"; cout << "a: length() = " << a.length() << "\n"; printlist(a); intSLList b = a; cout << "b = a: length() = " << b.length() << "\n"; printlist(b); cout << "remove_front of first 10 elements:\n"; for (i = 0; i < 10; ++i) cout << b.remove_front() << " "; cout << "\n"; cout << "b: length() = " << b.length() << "\n"; printlist(b); cout << "inserting after sixth element..."; intSLListTrav bp(b); for (i = 0; i < 5; ++i) bp.advance(); x = rand() % 100; cout << x << " "; bp.insert_after(x); cout << "\n"; cout << "b: length() = " << b.length() << "\n"; printlist(b); b.clear(); cout << "after b.clear() "; cout << "b: length() = " << b.length() << "\n"; printlist(b); intSLStack s; cout << "pushing all of a onto stack s..."; for (intSLListTrav ap = a; ap; ap.advance()) s.push(ap.get()); cout << "popping all of s:\n"; while (s) cout << s.pop() << " "; cout << "\n"; intSLQueue q; cout << "enqueueing all of a onto queue q..."; for (ap = a; ap; ap.advance()) q.enq(ap.get()); cout << "dequeueing all of q:\n"; while (q) cout << q.deq() << " "; cout << "\n"; intDLList y; cout << "intDLList y: length() = " << y.length() << "\n"; printDlist(y); cout << "prepending..."; for (i = 0; i < 10; ++i) { x = rand() % 100; cout << x << " "; y.prepend(x); } cout << "\n"; cout << "y: length() = " << y.length() << "\n"; printDlist(y); cout << "appending..."; for (i = 0; i < 10; ++i) { x = rand() % 100; cout << x << " "; y.append(x); } cout << "\n"; cout << "y: length() = " << y.length() << "\n"; printDlist(y); intDLList z = y; cout << "z = y: length() = " << z.length() << "\n"; printDlist(z); cout << "remove_front of first 10 elements:\n"; for (i = 0; i < 10; ++i) cout << z.remove_front() << " "; cout << "\n"; cout << "z: length() = " << z.length() << "\n"; printDlist(z); cout << "remove_rear of last 5 elements:\n"; for (i = 0; i < 5; ++i) cout << z.remove_rear() << " "; cout << "\n"; cout << "z: length() = " << z.length() << "\n"; printDlist(z); cout << "inserting before alternate elements..."; for (intDLListTrav zp(z); zp; zp.advance()) { x = rand() % 100; cout << x << " "; zp.insert_before(x); } cout << "\n"; cout << "z: length() = " << z.length() << "\n"; printDlist(z); cout << "inserting after sixth element..."; zp.reset(z); for (i = 0; i < 5; ++i) zp.advance(); x = rand() % 100; cout << x << " "; zp.insert_after(x); cout << "\n"; cout << "z: length() = " << z.length() << "\n"; printDlist(z); cout << "deleting alternate elements of z..."; for (zp.reset(); zp; zp.advance()) { cout << zp.get() << " "; zp.del(); } cout << "\n"; cout << "z: length() = " << z.length() << "\n"; printDlist(z); cout << "z in reverse order via traverser:\n"; for (zp.reset(-1); zp; zp.advance(-1)) cout << zp.get() << " "; cout << "\n"; z.clear(); cout << "after z.clear() "; cout << "z: length() = " << z.length() << "\n"; printDlist(z); cout << "\nEnd of test\n"; } End of test13.cc [part 2 of this message has been sent separately on account of length restrictions on e-mail; it contains the .h files]