Bug 63216

Summary: cpp parser breaks on compound literals
Product: [Applications] kdevelop Reporter: Richard Moats <rmoats-web>
Component: Language Support: CPP (old)Assignee: kdevelop-bugs-null
Status: RESOLVED DUPLICATE    
Severity: normal CC: esigra
Priority: NOR    
Version: git master   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Richard Moats 2003-08-25 04:32:16 UTC
Version:           3.0 CVS (8/23/03) (using KDE Devel)
Installed from:    Compiled sources
Compiler:          i686-pc-linux-gnu-gcc (GCC) 3.3.2 20030812 (Debian prerelease) 
OS:          Linux

When the cppparser runs into a compound literal in a function/method, it hiccups and causes other function-scope variables and function calls to appear as global symbols in the class browser:

void foo( float[2] );

void compoundLiteralTest()
{
  foo( (float[]){ 0.0f, 1.0f } );
  int anotherVar; // appears as global scope in the class browser
  ...
}

This construct parsed fine until these lines were added to Parse::skip() in lib/cppparser/parser.cpp (rev 1.3):

        else if( l != '{' && (tk == '{' || tk == '}' || tk == ';') )
            return false;

which causes Parse::skip( '(', ')' ) to error out while skipping through "( (float[]){ 0.0f, 1.0f } )"

While compound literals aren't legal in ANSI C++, they are in C99 and GNU C++ extensions...
Comment 1 Matt Rogers 2004-10-27 03:14:00 UTC
confirmed with CVS from 20041026
Comment 2 Michael Duelli 2007-01-04 23:17:25 UTC
Currently the parser of kdevelop from SVN does not accept this code at all, but as of gcc it is valid code and compiles fine.
Of couse, we can not check if it still produces a global symbol until the parser accepts this correct code again.
Comment 3 Andreas Pakulat 2007-11-30 16:37:10 UTC
This is basically the same thing as 57156, the parser from kdevelop simply isn't build for C.

*** This bug has been marked as a duplicate of 57156 ***
Comment 4 Aleix Pol 2013-03-31 00:49:32 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