Article View: gnu.g++.bug
Article #271Code that causes an infinite loop in g++ 2.1.
From: Gordon Joly
Date: Thu, 16 Apr 1992 17:28
Date: Thu, 16 Apr 1992 17:28
89 lines
3832 bytes
3832 bytes
#!/bin/sh
# GCC was configured as follows:
./configure --target=sparc-sun-sunos4.1
Whatever else, it seems strange to get a loop.
porridge:gjoly/c++/2.x[8] cat -n nibble.cc
1 // nibble.cc
2 // From: jimad@microsoft.com (Jim ADCOCK)
3
4 #include <stdio.h>
5
6 class bitref
7 {
8 unsigned char* byte;
9 unsigned bit;
10 static unsigned int index(unsigned i) { return i >> 3; }
11 static unsigned int offset(unsigned i) { return i & 7; }
12 public:
13 bitref(unsigned i, unsigned char* b) : bit(i), byte(b) {}
14 operator int() { return (byte[index(bit)] >> offset(bit)) & 1; }
15 const bitref& operator=(int i)
16 {
17 if (i) byte[index(bit)] |= (1U << offset(bit));
18 else byte[index(bit)] &= (~(1U << offset(bit)));
19 return *this;
20 }
21 };
22
23 /* questionable use of overloads, just for fun ;-) */
24 class bitset
25 {
26 int nbytes;
27 unsigned char* byte;
28 static unsigned int index(unsigned i) { return i >> 3; }
29 static unsigned int offset(unsigned i) { return i & 7; }
30 public:
31 bitset(unsigned i) { nbytes = index(i)+1U; byte = new unsigned char[nbytes]; }
32 ~bitset() { delete [] byte; }
33 bitset& operator+=(unsigned i)
34 { byte[index(i)] |= (1U << offset(i)); return *this;}
35 bitset& operator-=(unsigned i)
36 { byte[index(i)] &= (~(1U << offset(i))); return *this; }
37 bitref operator[](unsigned i) { return bitref(i, byte); }
38 bitset& reset();
39 bitset& set();
40 };
41 bitset& bitset::reset()
42 { for (int i=0; i<nbytes; ++i) byte[i] = 0; return *this; }
43 bitset& bitset::set()
44 { for (int i=0; i<nbytes; ++i) byte[i] = 0xFF; return *this; }
45
46
47 #define nbits 10000
48
49 main()
50 {
51 bitset sieve(nbits);
52 sieve.set();
53 printf("1\n");
54 for (unsigned i=2; i<nbits; ++i) if (sieve[i])
55 {
56 printf("%d\n", (int)i);
57 for (unsigned j=i; j<nbits; j+=i) sieve -= j;
58 }
59 return 0;
60 }
61
porridge:gjoly/c++/2.x[9] g++ -v -c nibble.cc
Reading specs from /cs/research/coside/local/croissant/lib/gcc-lib/sparc-sun-sunos4.1/2.1/specs
gcc version 2.1
/cs/research/coside/local/croissant/lib/gcc-lib/sparc-sun-sunos4.1/2.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix nibble.cc /usr/tmp/cca00973.i
GNU CPP version 2.1 (sparc)
/cs/research/coside/local/croissant/lib/gcc-lib/sparc-sun-sunos4.1/2.1/cc1plus /usr/tmp/cca00973.i -quiet -dumpbase nibble.cc -version -o /usr/tmp/cca00973.s
GNU C++ version 2.1 (sparc) compiled by CC.
nibble.cc: In method `const class bitref& bitref::operator = (int)':
nibble.cc:19: too few arguments for constructor `bitref'
nibble.cc:19: in conversion to type `bitref'
nibble.cc:19: too few arguments for constructor `bitref'
nibble.cc:19: in conversion to type `bitref'
the (Ctrl-C)^2 killed the proceess.
Gordon.
____
Gordon Joly +44 71 387 7050 ext 3703
Internet: G.Joly@cs.ucl.ac.uk UUCP: ...!{uunet,uknet}!ucl-cs!G.Joly
Computer Science, University College London, Gower Street, LONDON WC1E 6BT
Technical Details
Message-ID:
<9204161530.AA15395@life.ai.mit.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.ucl.ac.uk!G.JolyShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.ucl.ac.uk!G.Joly From: G.Joly@cs.ucl.ac.uk (Gordon Joly) Subject: Code that causes an infinite loop in g++ 2.1. Message-ID: <9204161530.AA15395@life.ai.mit.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 16 Apr 1992 17:28:54 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 90