Bug 273803 - macro-guarded system headers sometimes not parsed properly
Summary: macro-guarded system headers sometimes not parsed properly
Status: CONFIRMED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (old) (show other bugs)
Version: 4.6.0
Platform: Ubuntu Linux
: HI normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords: testcase
Depends on:
Blocks:
 
Reported: 2011-05-21 17:28 UTC by julee
Modified: 2021-03-09 22:47 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description julee 2011-05-21 17:28:40 UTC
Version:           4.2.60 (using KDE 4.6.3) 
OS:                Linux

Some system header files have been included in .cpp file,but it seems those included header files doesn't parse successfully sometimes!
It performs that when using those functions declared in those header files(such as time.h) ,  kdevelop shows those functions being not be  declared,and code completion doesn't work for those functions.
Howerver ,not all system header files couldn't be parsed, even   those system files cause this problem sometimes could be parsed successfully.
By the way,when meeting this problem,there is a way to make parsing  those system header files forcely,that is openning those system header files which included in source file but not parsed by kdevelop.

Reproducible: Sometimes

Steps to Reproduce:
1.Startup kdevelop.
2.Create a new simple cmake-based C++ project .
3.Open main.cpp,change its content like this:

#include <time.h>

int main(int argc, char **argv)
{
    time(NULL);
    return 0;
}
4.kdevelop show time not declared,and move cursor on function time,it shows not function tips.
5.In kdevelop's "quick open" editor bar,input "time.h" and select "/usr/include/time.h",/usr/include/time.h opend.Then activate main.cpp,now it shows the function time have been parsed,move cursor on function time,kdevelop will show function tips.

Actual Results:  
When not open some system header files with kdevelop,those header file will not be parsed,though they are be included in source file,and enough time have been given to make kdevelop to finish project parsing.

Expected Results:  
All system header files included in source files which  kdevelop  could addressed should be parsed automatically.

This bug is strange for its performance,it occurs frequently but not every time.But it's very very troublesome!
It appears since I use kdevelop 4 ,but  it doesn't be repaired at present.
Comment 1 julee 2011-05-21 17:46:17 UTC
May be others could repeat this bug with a new kdevelop session .Just click "Start new session" to click a new session,and close current session.Then create a new c++ project in the new session to test.
Comment 2 Milian Wolff 2011-05-27 18:08:19 UTC
easily reproduced. The reason is probably some issue with macro merging which leads to improper parsing of time.h...

David, any idea on how to debug this?
Comment 3 julee 2011-08-12 13:51:34 UTC
Now I wonder whether macro cause this bug!
Because I found this bug not only reproduced in macro-rich place such as system header files,but also for some larger  but with few simple macros project!
Further more, I can confirm function cannot parse could repaired just open that header file,and then reload all open files.
For example, I include time.h  in main.cpp,but  function time() still cannot parse after enough time.Then I can open the file time.h with kdevelop ,then reload main.cpp.After a while, function time() parsed successfully!

Is there a parsing optimization strategy for not open file ?Maybe this is the trouble maker.
Comment 4 Matěj Laitl 2014-07-08 11:08:58 UTC
I was able to reproduce this with time.h and KDevelop/Kdevplatfrom 4.6/1.6.

Let me speculate about the cause: time.h (and some similar glibc includes) seems to be a bit tricky (simplified to show the logic):

#ifndef	_TIME_H
#if (! defined __need_time_t && !defined __need_clock_t && \
     ! defined __need_timespec)
# define _TIME_H	1
#endif
(...)
#if defined _TIME_H || defined __need_time_t
typedef <something> time_t;
#endif

It essentially works in 2 ways:
 a) included by user code: no __need_something macros defined, so it defines _TIME_H and exports all functions and types. (what the user expects)
 b) included by other glibc header that defines some __needed_something macros: _TIME_H is not defined in this case and only requested functions or types are exported.

It looks like that KDevelop contains an optimisation that each file is parsed only once even if it occurs multiple times in dependency chain. That could explain why it doesn't see all symbols. Is that true?
Comment 5 Justin Zobel 2021-03-09 22:47:43 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 5 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.