This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 216764 - C99: Parser fails to parse enum members declared in a struct
Summary: C99: Parser fails to parse enum members declared in a struct
Status: RESOLVED FIXED
Alias: None
Product: cnd
Classification: Unclassified
Component: Code Model (show other bugs)
Version: 7.2
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Assignee: Alexander Simon
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-12 19:50 UTC by coops
Modified: 2014-02-13 02:45 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description coops 2012-08-12 19:50:52 UTC
struct a_struct {
    enum {
        foo, bar, baz
    } field;
};

int main(int argc, char *argv[]) {
    struct a_struct test;
    test.field = foo;
}

/* This code is completely valid c99 and will run and execute without problem
with -std=c99. However the Netbeans parser breaks and reports "Unable to
resolve identifier foo" making Netbeans programming in source code containing
this pattern impossible. */
Comment 1 Alexander Pepin 2012-08-15 09:47:12 UTC
The code is not compilable
...
g++    -c -g -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:20: error: ‘foo’ was not declared in this scope
make[2]: *** [build/Debug/Cygwin_4.x-Windows/main.o] Error 1
make[2]: Leaving directory `/cygdrive/c/Users/ap153252/Documents/NetBeansProjects/CppApplication_3'
make[1]: Leaving directory `/cygdrive/c/Users/ap153252/Documents/NetBeansProjects/CppApplication_3'
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 19s)

The parser works fine if you improve your code e.g.
...
    test.field = a_struct::foo;
...
Comment 2 Vladimir Voskresensky 2012-08-15 14:15:38 UTC
Alexander, have you checked C compiler with c99 standard? Looks like you tried C++ with default standard. 

It is not P1 blocker issue. Changing priority as well.
Comment 3 coops 2012-08-16 10:30:07 UTC
(In reply to comment #1)
> The code is not compilable
> ...
> g++    -c -g -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d -o
> build/Debug/Cygwin_4.x-Windows/main.o main.cpp
> main.cpp: In function ‘int main(int, char**)’:
> main.cpp:20: error: ‘foo’ was not declared in this scope
> make[2]: *** [build/Debug/Cygwin_4.x-Windows/main.o] Error 1
> make[2]: Leaving directory
> `/cygdrive/c/Users/ap153252/Documents/NetBeansProjects/CppApplication_3'
> make[1]: Leaving directory
> `/cygdrive/c/Users/ap153252/Documents/NetBeansProjects/CppApplication_3'
> make[1]: *** [.build-conf] Error 2
> make: *** [.build-impl] Error 2
> 
> 
> BUILD FAILED (exit value 2, total time: 19s)
> 
> The parser works fine if you improve your code e.g.
> ...
>     test.field = a_struct::foo;
> ...

Why are you using C++? This is C99...
Comment 4 Gulzt 2013-09-21 20:08:39 UTC
I can confirm this bug. 

I just stumbled upon the same problem where I declared a struct containing an enum in a header file.

In the complementing .c file the enum values  produce the mentioned error:
"unable to resolve identifier (...)"

For some reason, if I copy-paste the struct declaration to the .c file, the errors disappear. Of course, this is not a solution. It will only spark a ton of "redeclation of enumerator (...) errors.

I can't find a solid workaround. It is indeed valid code in c99, so a bug in netbeans.
Comment 5 Alexander Simon 2014-02-12 18:33:36 UTC
fixed, change set:
http://hg.netbeans.org/cnd-main/rev/f2ca4012c1f1
Comment 6 Quality Engineering 2014-02-13 02:45:22 UTC
Integrated into 'main-silver', will be available in build *201402130001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/f2ca4012c1f1
User: Alexander Simon <alexvsimon@netbeans.org>
Log: ficed Bug #216764 C99: Parser fails to parse enum members declared in a struct