Bug 109015 - g++ hangs forever
Summary: g++ hangs forever
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 8.0
Hardware: All
OS: Linux
high
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-11-04 13:43 UTC by Chandra Shekhar Kumar
Modified: 2005-10-31 22:00 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-10-04 06:06:10 UTC
Embargoed:


Attachments (Terms of Use)

Description Chandra Shekhar Kumar 2003-11-04 13:43:05 UTC
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 15:30:57 UTC
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 18:59:58 UTC
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 14:30:43 UTC
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 06:06:10 UTC
Indeed.  Not a bug.


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