code completion

Jens Dagerbo jens.dagerbo at swipnet.se
Sat Mar 27 18:28:06 UTC 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 26 March 2004 18:17, Daniel Franke wrote:
> 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
>

Unsurprisingly, the Code Completion is wrong, gcc is correct. For a B object, 
only the print() method that B defines is available.

Quoting Eckel:
"If a base class has a function name that's overloaded several times, 
redefining that function name in the derived class will hide _all_ the 
base-class versions."

I don't think this is the worst bug in the CC mechanism, but it is incorrect 
and should probably be reported. ;)

jd

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAZbke6meJzsUuplQRAoL/AJwLSK9amvOpSOUfEW6yQUuhlLu/dgCePl2b
t24keiTUZG7untz5LcCbZiE=
=NHTm
-----END PGP SIGNATURE-----




More information about the KDevelop-devel mailing list