bug report for egcs-1.1b on linux-2.0.31-glibc-2.0.5

Vasilis Samoladas vsam@cs.utexas.edu
Sun Nov 22 06:55:00 GMT 1998


Hi,

the following file contains a bug report. Just cut the rest of this message and save it in file buglib.cc.

----------- CUT HERE --------------------
// Bug report
// ----------

// The following program exposes a bug in the egcs-1.1b C++ compiler,
// in conjuncion with system libraries.

// The program is a C program, as well as a C++ program. The C 
// compiler works fine.

// Versions:

// % /opt/bin/g++ -v
// Reading specs from /opt/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.91.57/specs
// gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

// Compiler output:
// % /opt/bin/g++ -c buglib.cc
// buglib.cc: In function `int main()':
// buglib.cc:64: `wait_status' undeclared (first use this function)
// buglib.cc:64: (Each undeclared identifier is reported only once
// buglib.cc:64: for each function it appears in.)
// buglib.cc:64: warning: ANSI C++ forbids declaration `__in' with no type

// ---------  example program -------------------

// -*- c++ -*-

// This program exposes a bug in the egcs-1.1b C++ compiler, when used in
// conjunction with glibc-2.0.5 on linux-2.0.31

// The program is a pretty straight-forward piece of code for checking the
// exit status of a fork() 'ed child process.

// The error exposed is almost certainly in the compiler, as the error
// message is "Undeclared identifier".

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main() {

  pid_t child_pid;
  int wait_status;

  // here we fork
  switch( child_pid = fork() ) {
    
  case -1:			// fork has failed
    printf("An error occurred !\n");
    break;
    
  case 0:			// child process
    printf("This is the child !\n");
    break;
    
  default:			// parent process
    
    // wait for child to finish
    while(child_pid != wait(&wait_status));
    
    // check child exit status
    if(WIFEXITED(wait_status))	// THIS IS THE OFFENDING LINE
      printf("Child exited ok.\n");
    else
      printf("Child exited with errors.\n");
    
  }
  
  return 0;
}
       

// Output of preprocessor (truncated):

// % /opt/bin/g++ -E buglib.cc

// ............ (stuff deleted)

// # 40 "buglib.cc" 2


// int main() {

//   pid_t child_pid;
//   int wait_status;

   
//   switch( child_pid = fork() ) {
    
//   case -1:                       
//     printf("An error occurred !\n");
//     break;
    
//   case 0:                        
//     printf("This is the child !\n");
//     break;
    
//   default:                       
    
     
//     while(child_pid != wait(&wait_status));
    
     
//     if((((  (__extension__ ({ union { __typeof(  wait_status  ) __in; int __i; }
//  __u;   __u.__in = (  wait_status  ); __u.__i; }))   ) & 0x7f)  == 0)  )        
//       printf("Child exited ok.\n");
//     else
//       printf("Child exited with errors.\n");
    
//   }
  
//   return 0;
// }

// ------ further notices ------------------------

// after experimenting with the preprocessed output, I have located the 
// error in the __typeof( wait_status ) portion. If the code is replaced 
// by "int", the code compiles fine. 

// I have also:
// (*) removed __extension__  and/or
// (*) replaced __typeof with __typeof__ / typeof
// but the error persisted.




More information about the Gcc-bugs mailing list