Bug 94933

Summary: extern "C" Bug in classview-part
Product: [Applications] kdevelop Reporter: Robert Gruber <rgruber>
Component: Language Support: CPP (old)Assignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal CC: kdevelop-devel, roberto
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: see my post above from 05.01.2005

Description Robert Gruber 2004-12-11 17:32:33 UTC
Version:           CVS HEAD (using KDE KDE 3.2.1)
Installed from:    SuSE RPMs
Compiler:          gcc (GCC) 3.3.3 (SuSE Linux) 
OS:                Linux

I came across a very strange behavior of the classview-part today.

I've got a C function which is declared >extern "C"< in the .h file and is defined in the corresponding .cc file. Somehow it does not show up in the classview.

Totaly confused I checked kdevelop's source for files using >extern "C"<. 
It seams, that if you embedd the >extern "C"< into >#ifdef __cplusplus< everything inside >extern "C"< gets ignored.

The really strange about this is, that it only doesn't work with >#ifdef __cplusplus<. Any other ifdef works just fine (For example >#ifdef __cplusplus__< or even >#ifdef ANYTHING< works)

To me this looks like either the cpp-parser or the classview-part has a nasty bug.

Greeting, 
    Robert


Just to make sure, the files I tested this miss-behavior with looked like this:

--- test_DONTWORK.h
//this funcion does NOT show up in classview
#ifdef __cplusplus
extern "C" {
#endif
  
  void foo1();

#ifdef __cplusplus
}
#endif
--- test_DONTWORK.h

--- test_WORKS.h
//this function DOES show up in classview
#ifdef __cplusplus__
extern "C" {
#endif
  
  void foo2();

#ifdef __cplusplus__
}
#endif
--- test_WORKS.h

--- test_WORKS_TOO.h
//this function DOES show up in classview
#ifdef THIS_IS_A_TEST
extern "C" {
#endif
  
  void foo3();

#ifdef THIS_IS_A_TEST
}
#endif
--- test_WORKS_TOO.h
Comment 1 Robert Gruber 2005-01-05 19:44:16 UTC
Hi,

I've hacked into cpp-parser the last three days an I think I've found both the problem an a possible solution for my bugreport.

It seams that this happens (lib/cppparser/parser.cpp):
*) parseLinkageSpecification() creates a LinkageBodyAST object and stores the declarations (which are declared inside the extern "C") in it
*) parseLinkageSpecification() then saves the created object as linkageBody and returns
*) back in parseTranslationUnit() the parsers continues with the next declaration

To me it looks like nowhere anything is done with the declarations stored in the linkageBody. They are lost!

I did a small patch to the parseTranslationUnit() function which worked well with my test projects.

I've attached the output of "cvs diff" to this bug (http://bugs.kde.org/show_bug.cgi?id=94933). Could anybody who really knows what is happening inside the cpp-parser please review this patch and contact me!?

Greets, Robert


---
Robert Gruber -=- rgruber (-a-) users.sourceforge.net
Comment 2 Robert Gruber 2005-01-05 19:46:02 UTC
Created attachment 8935 [details]
see my post above from 05.01.2005
Comment 3 Jens Dagerbo 2005-01-05 23:22:52 UTC
Roberto, any chance you could offer some insight?
Comment 4 Andreas Pakulat 2007-11-30 20:42:34 UTC
Quite old bug. I don't know the C++ parser in kdev3, but the patch looks ok to me. Anybody has some objections against comitting this?
Comment 5 Andreas Pakulat 2008-07-05 22:30:21 UTC
works in kdevelop4.
Comment 6 Aleix Pol 2013-03-31 00:53:27 UTC
Moving all the bugs from the CPP Parser. It was not well defined the difference between it and C++ Language Support and people kept reporting in both places indistinctively