This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/1927: internal compiler error 980711
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/1927: internal compiler error 980711
- From: gilles56 at escape dot ca
- Date: 10 Feb 2001 18:49:35 -0000
- Reply-To: gilles56 at escape dot ca
>Number: 1927
>Category: c++
>Synopsis: internal compiler error 980711
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: ice-on-legal-code
>Submitter-Id: net
>Arrival-Date: Sat Feb 10 10:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: gilles56@escape.ca
>Release: egcs 1.1.2 GCC 2.91.66
>Organization:
>Environment:
Linux 6.0 OS
>Description:
internal compiler error 980711
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="full_grading.txt"
Content-Disposition: inline; filename="full_grading.txt"
the following program has 7 parts: median.h, median.cc; grade.h, grade.cc;
Student_info.h, Student_info.cc; and the main function: 4_grading.cc.
I received an internal error 980711 with version egcs 2.91.66 with command:
g++ -o 4_grading median.cc Student_info.cc grade.cc 4_grading.cc
////////////////////////////////////////////////////////////
#ifndef GUARD_median_h
#define GUARD_median_h
//median.h
#include <vector>
double median(std::vector<double>);
#endif
//////////////////////////////////////////////////////////
//median.cc
#include <algorithm> //for declaration of sort
#include <stdexcept> //for declaration of domain_error
#include <vector> //for kdeclaration of vector
#include "median.h"
using std::domain_error; using std::sort; using std::vector;
//compute the median of a vector<double>
double median(vector<double> vec)
{
typedef vector<double>::size_type vec_sz;
vec_sz size = vec.size();
if(size == 0 )
throw domain_error("median of an empty vector");
sort(vec.begin(), vec.end());
vec_sz mid = size/2;
return size % 2 == 0 ? (vec[mid] + vec[mid-1]) / 2 : vec[mid];
}
/////////////////////////////////////////////////////////////
#ifndef GUARD_grade_h
#define GUARD_grade_h
//grade.h
#include <vector>
#include "Student_info.h"
double grade(double, double, double);
double grade(double, double, const std::vector<double>&);
double grade(const Student_info&); //requires Student_info.h
#endif
//////////////////////////////////////////////////////////
//grade.cc
#include <stdexcept>
#include <vector>
#include "grade.h"
#include "median.h"
#include "Student_info.h"
using std::domain_error; using std::vector;
double grade(double midterm, double final, double homework)
{
return 0.2 * midterm + 0.4 * final + 0.4 * homework;
}
double grade(double midterm, double final, const vector<double>& hw)
{
if(hw.size == 0)
throw domain_error("student has done no homework");
return grade(midterm, final, median(hw));
}
double grade(const Student_info& s)
{
return grade(s.midterm, s.final, s.homework);
}
/////////////////////////////////////////////////////////
#ifndef GUARD_Student_info
#define GUARD_Student_info
//Student_info.h
#include <iostream>
#include <string>
#include <vector>
struct Student_info (
std::string name;
double midterm, final;
std::vector<double> homework;
};
bool compare(const Student_info&, const Student_info&);
std::istream& read(std::istream&, Student_info&);
std::istream& read_hw(std::istream&, std::vector<double>&);
#endif
//////////////////////////////////////////////////
//Student_info.cc
#include "Student_info.h"
using std::istream; using std::vector;
bool compare(const Student_info& x, const Student_info& y)
{
return x.name < y.name;
}
istream& read(istream& is, Student_info& s)
{
is >> s.name >> s.midterm >> s.final;
read_hw(is, s.homework); //homework from grade function
return is;
}
istream& read_hw(istream& in, vector<double>& hw)
{
if(in) {
hw.clear();
double x;
while(in >> x)
hw.push_back(x);
in.clear();
}
return in;
}
////////////////////////////////////////////////////////////
//main function
//4_grading.cc
#include <algorithm>
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <stdexcept>
#include <string>
#include <vector>
#include "grade.h"
#include "Student_info.h"
using std::cin; using std::sort;
using std::cout; using std::streamsize;
using std::domain_error; using std::string;
using std::endl; using std::vector;
using std::max; using std::setw;
using std::setprecision;
int main()
{
vector<Student_info> students;
Student_info record;
string::size_type maxlen = 0;
while(read(cin,record)) {
maxlen = max(maxlen, record.name.size());
students.push_back(record);
}
sort(students.begin(), students.end(), compare);
for(vector<Student_info>::size_type i = 0;
i != students.size(); ++i) {
cout << setw(maxlen+1) << students[i].name;
try {
double final_grade = grade(students[i]);
streamsize prec = cout.precision();
cout << setprecision(3) << final_grade
<< setprecision(prec);
} catch (domain_error e) {
cout << e.what();
}
cout << endl;
}
return 0;
}