jj@idris.id.dk (Jesper Joergensen [ris]) (01/19/90)
This is an IMPORTANT followup on a Looooonng bug report I posted yesterday,
where I included a lot of preprocessed source code, so that you could reproduce
the BUG. The compiler crashes with a "segmentation violation", while processing
a constructor call in value context, i.e. inside an expression.
I have now ISOLATED the BUG and found that my program was illegal with respect
to the member function visibility of C++, as soon as I corrected the visibility
of the function in question no compiler crash occured.
Below is two examples which will demonstrate the problem thoroughly, one with
and one without compiler crash.
I AM VERY SORRY THAT I TROUBLED YOU WITH THE LONG POSTING YESTERDAY, BUT I
COULDN'T ISOLATE THE BUG AT THAT TIME (next time I won't submit bug reports
late in the evening).
****** Example WITHOUT CRASH start ******
class Test {
int member ;
public:
Test(int member1) {
member = member1 ;
}
} ;
int main(int argc, const char *argv[]) {
Test x(2) ;
x = Test(7) ;
return 0 ;
}
******* Example WITHOUT CRASH end *******
The above example compiles without any errors of any kind, since there aren't
any (knock, knock ... :^). However, if the constructor is made private, as in
the below example, the compiler will crash instead of making a suitable error
message.
******* Example WITH CRASH start *******
class Test {
int member ;
Test(int member1) {
member = member1 ;
}
public:
} ;
int main(int argc, const char *argv[]) {
Test x(2) ;
x = Test(7) ; // This is the offending line
return 0 ;
}
******** Example WITH CRASH end ********
When running the compiler on the above example I get the following output.
******** CRAHS compilation start ********
% pwd
/usr/users/jj/ruby/id
% g++ -v ctortest.cc -O -S
g++ version 1.36.3- (based on GCC 1.36)
/usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dvax -Dunix -D__vax__ -D__unix__ -D__OPTIMIZE__ ctortest.cc /usr/tmp/cc021595.cpp
GNU CPP version 1.36
/usr/local/lib/gcc-cc1plus /usr/tmp/cc021595.cpp -quiet -dumpbase ctortest.cc -O -version -o ctortest.s
GNU C++ version 1.36.3- (based on GCC 1.36) (vax) compiled by GNU C version 1.36.
default target switches: -munix
ctortest.cc:7: warning: all class member functions are private
ctortest.cc:7: warning: class Test only defines private constructors and has no friends
ctortest.cc: In function int main (int, const char **):
ctortest.cc:10: constructor `Test::Test (int)' is private
ctortest.cc:10: in base initialization for class `Test'
ctortest.cc:11: Segmentation violation
g++: Program cc1plus got fatal signal 11.
********* CRAHS compilation end *********
All the leading error messages are correct, due to the illegal use of the
private constructor. The use within value context in line 11, however results
in a crash instead of an error message.
That should be all, oh BTW
I am using: g++ version 1.36.3-
based on: gcc version 1.36
under: Ultrix V2.2-1 Worksystem V1.1 System #2
on a: DEC VAXstation 2000
though I don't think that has anything to do with the bug.
Once again I apologize for having troubled you with the long posting yesterday.
Good luck, hopes this clarification helps
Jesper Jorgensen jj@idris.id.dk
Research associate
Department of Computer Science
Technical University of Denmark
DK-2800 Lyngby
DENMARK