Bug 265975

Summary: c++ parser doesn't support designated initializers (C99 feature)
Product: [Applications] kdevelop Reporter: Andrej Krutak <lists>
Component: Language Support: CPP (old)Assignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 4.2.0   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In: 5.0.0

Description Andrej Krutak 2011-02-10 11:44:42 UTC
Version:           4.2.0 (using KDE 4.6.0) 
OS:                Linux

When given the following (valid) lines of code, the cpp parser doesn't parse them - instead it says there's an error.


Reproducible: Always

Steps to Reproduce:
/* error at [ inside initialization */
static char buffer[TESTDATA_LENGTH] = { [0 ... TESTDATA_LENGTH - 1] = 0 };

/* error at 'c' in (char*[]) */
char **blah = (char *[]){"abc", "def", NULL};


Expected Results:  
both constructs are valid and compilable (at least using gcc)
Comment 1 Milian Wolff 2013-01-09 21:01:04 UTC
Without any special flags I cannot compile this using g++ - this is non-standard anyways, or?

Anyways, I'll need a full, compilable minimal example along with the g++ invocation required to compile it. Also a link to the standard that explains this syntax.

What I could understand (but is properly parsed by KDevelop afaik) is the brace-initializer syntax from C++11:

const char *blah[2] = {"abc", "def"};
Comment 2 Kevin Funk 2013-01-09 21:14:00 UTC
They are both C constructs, compiles fine for me in C99 mode.

- Feature 1 is called 'designated initializers' (http://tigcc.ticalc.org/doc/gnuexts.html#SEC82)
- Feature 2 is using 'compound literals' on the right side of the assignment (http://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Compound-Literals.html)  - but the report is a duplicate of https://bugs.kde.org/show_bug.cgi?id=246026 (which I have a fix for in the pipeline)
Comment 3 Kevin Funk 2013-01-09 21:21:59 UTC
I'm fixing the bug title;

The issue is that designated initializers
"static char buffer[TESTDATA_LENGTH] = { [0 ... TESTDATA_LENGTH - 1] = 0 };" 
are not recognized.

Here's another issue dealing with *structure* initializers: https://bugs.kde.org/show_bug.cgi?id=280591 (structure initializers are a subset of designated initializers).
Comment 4 Kevin Funk 2016-09-08 19:59:04 UTC
Hello!

We worked on a new clang-based C/C++ language plugin for KDevelop 5 which
supersedes the old C++ plugin in KDevelop 4. See e.g.:
https://www.kdevelop.org/news/first-beta-release-kdevelop-500-available
https://www.kdevelop.org/news/kdevelop-500-released

Due to a lack of manpower, we cannot fix bugs in the old C++ plugin. We rather
want to supply a good Clang based C++ experience for KDevelop 5 than wasting
our time on the legacy C++ support for KDevelop 4.

With the new clang-based C/C++ language plugin, the bug presented here does not
occur in my testing. For these reasons, I'll close this bug. Please try out
KDevelop 5, either by downloading it through your distro, or by playing around
with the AppImage:.

If you think this bug is applicable to Clang/KDevelop 5, please reopen the
report and add new information on how to reproduce the bug there.

Sorry for the inconvenience, I hope you understand the reasoning above.

Cheers
Comment 5 Andrej Krutak 2016-09-21 07:36:30 UTC
In kdevelop5 it really looks OK. Thanks for all the clang work, great stuff!