code completion

Daniel Franke daniel.franke at imbs.uni-luebeck.de
Fri Mar 26 18:16:02 UTC 2004


Hi all!

I had fun with gcc and code completion yesterday evening. I assume, one of
them fools me, but I don't know which ...

Assume two simple classes (stripped down example):
--
class A {
public:
	void print(const string& t) { print(t.c_str()); }
	virtual void print(const char *s) { cout << "A: " << s; }
};

class B : public A {
public:
	void print(const char *s) { cout << "B: " << s; }
};
--

and a short code snipplet:

--
string hello = "Hello";
A *a = new B;
a->[ctrl+space]
--
Here code completion offers both print-methods, therefore:
--
string hello = "Hello";
A *a = new B;
a->print(hello)
--
As expected, gcc compiles the code, "Hello" is printed at stdout.

A small change:
--
string hello = "Hello";
B *b = new B;
b->[ctrl+space]
--
Again, code completion offers both print methods.
--
string hello = "Hello";
B *b = new B;
b->print(hello);
--
gcc complains:
--
home/daniel/cvs/test/src/test.cpp: In function `int main(int, char**)':
/home/daniel/cvs/test/src/test.cpp:51: error: no matching function for
call to `B::print(std::string)'
/home/daniel/cvs/test/src/test.cpp:42: error: candidates are: virtual void
B::print(const char*)
--

Therefore, either code completion shouldn't offer derived methods when
they are not available - or gcc should have a closer look?

I don't know - is there a bug, and if yes, where?

	Daniel


version:
kdevelop 3.0.2 (KDE-3.2.1 release)
gcc-3.3.1 (SuSE 9.0)







More information about the KDevelop-devel mailing list