Bug 109015 - g++ hangs forever
g++ hangs forever
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
8.0
All Linux
high Severity high
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-11-04 08:43 EST by Chandra Shekhar Kumar
Modified: 2005-10-31 17:00 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-10-04 02:06:10 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Chandra Shekhar Kumar 2003-11-04 08:43:05 EST
Description of problem:
Try to compile this file named ansi.cpp: with g++ ansi.cpp
-----------------------------------------------------------------
template<int Depth, int A, typename B>
struct K17 {
        static const int x =
                K17<Depth+1, 0, K17<Depth,A,B> >::x
                + K17<Depth+1, 1, K17<Depth,A,B> >::x
                + K17<Depth+1, 2, K17<Depth,A,B> >::x
                + K17<Depth+1, 3, K17<Depth,A,B> >::x
                + K17<Depth+1, 4, K17<Depth,A,B> >::x;
        };
        template<int A, typename B>
        struct K17<16,A,B> {
        static const int x = 1;


};
static const int z = K17<0,0,int>::x;

----------------------------------------------------------------



Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. g++ ansi.cpp
2.
3.
  
Actual results:
it hangs forever..

Expected results:
it should compile

Additional info:
Comment 1 Michael Lee Yohe 2003-11-04 10:30:57 EST
If you monitor "top" whilst compiling you'll see that the process is
gradually increasing in size.  Something does, indeed, appear to be
horked.

$ g++ --version
g++ (GCC) 3.3.1 20030915 (Red Hat Linux 3.3.1-5)
Comment 2 Maciej Żenczykowski 2003-11-06 13:59:58 EST
You're declaring approximately 5^16==152587890625 structs (actually
exactly 5^16+5^15+5^14+...+5^2+5^1+1), how do you expect this to compile?

Besides this is a typical example of what not to do with templates.
Not to mention the fact that typename B and int A can both be removed
without affecting the program.

Oh, and even if it somehow managed to compile you'll still have the
wrong value for z as it will overflow a 32-bit int.

By the way your code is equivalent to
static const int z = -2030932031;
Comment 3 Pieter Eendebak 2003-11-24 09:30:43 EST
The comment from maze above is entirely correct. The problem is not a
bu g in the compiler or somewhere else but the fact that the problem
gets to large to compile. For example by replacing the constant 16 by
3 the program compiles without a problem.

Comment 4 Richard Henderson 2004-10-04 02:06:10 EDT
Indeed.  Not a bug.

Note You need to log in before you can comment on or make changes to this bug.