From: hansb@aie.nl (Hans Bayle)
Subject: LPI C++ bug
Organization: AI Engineering BV, Amsterdam, The Netherlands
Date: Thu, 12 Nov 1992 11:27:34 GMT


This is a bug report for Liant LPI C++, version 01.00.08 for Interactive
Unix 386/ix.
When using the debug option, (-g with lpicxx, or -deb with lpi++) the
calling of methods in objects in which a virtual method is defined will
result in executing the wrong methods, or causing a segmentation fault (when
run in Codewatch as well as run stand alone)
Without the debug option, the code will run correctly. Unfortunately,
the debug option is needed for the source level debugger Codewatch.
So most C++ code will not run when compiled for Codewatch :(
I isolated the bug in the shar archive beneath.


-- Hans Bayle

-------------------------- cut here ---------------------------------------
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 11/12/1992 10:03 UTC by hansb@aie7
# Source directory /usr7/hansb/lpi-bug
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    427 -rw-r--r-- Makefile
#    116 -rw-r--r-- subclass.h
#    133 -rw-r--r-- superclass.h
#    253 -rw-r--r-- main.c
#    127 -rw-r--r-- subclass.c
#    237 -rw-r--r-- superclass.c
#
# ============= Makefile ==============
if test -f 'Makefile' -a X"$1" != X"-c"; then
	echo 'x - skipping Makefile (File already exists)'
else
echo 'x - extracting Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
# File: Makefile
X
CCXX = lpicxx
X
# uncomment the next line for causing the bug
#CFLAGS = -g 
X
test: main.o superclass.o subclass.o
X	$(CCXX) $(CFLAGS) main.o superclass.o subclass.o -o test 
X
main.o: main.c
X	$(CCXX) $(CFLAGS) -c main.c
X
superclass.o: superclass.c superclass.h
X	$(CCXX) $(CFLAGS) -c superclass.c
X
subclass.o: subclass.c superclass.h subclass.h
X	$(CCXX) $(CFLAGS) -c subclass.c
X
clean:
X	rm -f core *.stb test *.o
SHAR_EOF
chmod 0644 Makefile ||
echo 'restore of Makefile failed'
Wc_c="`wc -c < 'Makefile'`"
test 427 -eq "$Wc_c" ||
	echo 'Makefile: original size 427, current size' "$Wc_c"
fi
# ============= subclass.h ==============
if test -f 'subclass.h' -a X"$1" != X"-c"; then
	echo 'x - skipping subclass.h (File already exists)'
else
echo 'x - extracting subclass.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'subclass.h' &&
// File: subclass.h
X
#include "superclass.h"
X
class subclass: public superclass {
public:
X	void bug(char* text);
};
SHAR_EOF
chmod 0644 subclass.h ||
echo 'restore of subclass.h failed'
Wc_c="`wc -c < 'subclass.h'`"
test 116 -eq "$Wc_c" ||
	echo 'subclass.h: original size 116, current size' "$Wc_c"
fi
# ============= superclass.h ==============
if test -f 'superclass.h' -a X"$1" != X"-c"; then
	echo 'x - skipping superclass.h (File already exists)'
else
echo 'x - extracting superclass.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'superclass.h' &&
// File: superclass.h
X
#include <stdio.h>
X
class superclass {
X    public:
X	virtual void bug(char*);
X	virtual void alsobug(char*);
};
SHAR_EOF
chmod 0644 superclass.h ||
echo 'restore of superclass.h failed'
Wc_c="`wc -c < 'superclass.h'`"
test 133 -eq "$Wc_c" ||
	echo 'superclass.h: original size 133, current size' "$Wc_c"
fi
# ============= main.c ==============
if test -f 'main.c' -a X"$1" != X"-c"; then
	echo 'x - skipping main.c (File already exists)'
else
echo 'x - extracting main.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&
// File: main.c
X
#include "subclass.h"
X
main()
{
X    subclass *foo = new subclass; // foo is ptr to object of class subclass
X
X    foo->alsobug("hi");	// the wrong method will be called here
X    foo->bug("hi");		// this will cause a segmentation fault
}
SHAR_EOF
chmod 0644 main.c ||
echo 'restore of main.c failed'
Wc_c="`wc -c < 'main.c'`"
test 253 -eq "$Wc_c" ||
	echo 'main.c: original size 253, current size' "$Wc_c"
fi
# ============= subclass.c ==============
if test -f 'subclass.c' -a X"$1" != X"-c"; then
	echo 'x - skipping subclass.c (File already exists)'
else
echo 'x - extracting subclass.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'subclass.c' &&
// File: subclass.h
X
#include "subclass.h"
X
void subclass::bug(char* text)
{
X  printf("subclass::bug() prints: %s\n", text);
}
SHAR_EOF
chmod 0644 subclass.c ||
echo 'restore of subclass.c failed'
Wc_c="`wc -c < 'subclass.c'`"
test 127 -eq "$Wc_c" ||
	echo 'subclass.c: original size 127, current size' "$Wc_c"
fi
# ============= superclass.c ==============
if test -f 'superclass.c' -a X"$1" != X"-c"; then
	echo 'x - skipping superclass.c (File already exists)'
else
echo 'x - extracting superclass.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'superclass.c' &&
// File: superclass.c
X
#include "superclass.h"
X
void superclass::bug(char * text) {
X    printf("superclass::bug() prints: %s\n", text);
}
X
void superclass::alsobug(char * text) {
X    printf("superclass::alsobug() prints: %s\n", text);
}
SHAR_EOF
chmod 0644 superclass.c ||
echo 'restore of superclass.c failed'
Wc_c="`wc -c < 'superclass.c'`"
test 237 -eq "$Wc_c" ||
	echo 'superclass.c: original size 237, current size' "$Wc_c"
fi
exit 0
Newsgroups: comp.lang.c++