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 269453 - Unable to resolve identifier for auto-declared range declaration in C++11 range based for loop for pointer types
Summary: Unable to resolve identifier for auto-declared range declaration in C++11 ran...
Status: REOPENED
Alias: None
Product: cnd
Classification: Unclassified
Component: Code Model (show other bugs)
Version: Dev
Hardware: PC Linux
: P3 normal (vote)
Assignee: petrk
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-30 04:35 UTC by Otisburg
Modified: 2017-12-01 15:48 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
screenshot - red underline (52.10 KB, image/png)
2017-01-10 02:53 UTC, Otisburg
Details
screenshot - "Unable to resolve identifier" popup (51.20 KB, image/png)
2017-01-10 02:55 UTC, Otisburg
Details
sample project (16.93 KB, application/zip)
2017-01-11 01:51 UTC, Otisburg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Otisburg 2016-12-30 04:35:15 UTC
The following code is valid C++11/C++14:

#include <iostream>
#include <vector>

using namespace std;

struct A
{
    void SomeMemberFunction()
    {
        cout << "Hello\n";
    }
};


int main()
{
    vector<A*> vector_of_ptrs_to_A;
    vector_of_ptrs_to_A.push_back( new A() );
    
    for ( auto& e : vector_of_ptrs_to_A )
    {
        //"Unable to resolve identifier SomeMemberFunction."
        e->SomeMemberFunction();
    }
    
    auto& elem = vector_of_ptrs_to_A.front();
    elem->SomeMemberFunction();
}

But the editor is unable to resolve the identifier for the member function "SomeMemberFunction()" when called on the pointer variable "e" in the range based for loop.

Here is my Netbeans version info:

Product Version: NetBeans IDE Dev (Build 201611020002)
Java: 1.8.0_111; OpenJDK 64-Bit Server VM 25.111-b14
Runtime: OpenJDK Runtime Environment 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14
System: Linux version 4.4.0-21-generic running on amd64; UTF-8; en_US (nb)
Comment 1 Otisburg 2016-12-30 15:09:56 UTC
Added more test cases.  All of the new test cases compile and run, and are resolvable by the editor.  Only the "auto" declaration in the range based for loop is unresolvable by the editor.

#include <iostream>
#include <vector>

using namespace std;

struct A
{
    void SomeMemberFunction()
    {
        cout << "Hello\n";
    }
};


int main()
{
    vector<A*> vector_of_ptrs_to_A;
    vector_of_ptrs_to_A.push_back( new A() );
    
    for ( auto& e : vector_of_ptrs_to_A )
    {
        //"Unable to resolve identifier SomeMemberFunction."
        e->SomeMemberFunction();
    }
    
    for ( A*& e : vector_of_ptrs_to_A )
    {
        e->SomeMemberFunction(); //Netbeans can resolve this just fine.
    }
    
    for ( A* e : vector_of_ptrs_to_A )
    {
        e->SomeMemberFunction(); //Netbeans can resolve this just fine.
    }
    
    for ( decltype( vector_of_ptrs_to_A )::value_type& e : vector_of_ptrs_to_A )
    {
        e->SomeMemberFunction(); //Netbeans can resolve this just fine.
    }

    auto& elem = vector_of_ptrs_to_A.front();
    elem->SomeMemberFunction();
}
Comment 2 petrk 2017-01-09 12:02:35 UTC
What is your compiler? Seems to be related with compiler stl, because with gcc 6.2.0 and gcc 5.3.0 it works fine.
Comment 3 Otisburg 2017-01-10 02:53:26 UTC
Created attachment 163365 [details]
screenshot - red underline
Comment 4 Otisburg 2017-01-10 02:55:59 UTC
Created attachment 163366 [details]
screenshot - "Unable to resolve identifier" popup
Comment 5 Otisburg 2017-01-10 02:57:18 UTC
(In reply to petrk from comment #2)
> What is your compiler? Seems to be related with compiler stl, because with
> gcc 6.2.0 and gcc 5.3.0 it works fine.

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

---

Just to reiterate, I'm able to compile and run just fine. The error is in the editor/code assistance.  Please see attached screenshots.
Comment 6 petrk 2017-01-10 11:01:58 UTC
> Just to reiterate, I'm able to compile and run just fine. The error is in the editor/code assistance.  Please see attached screenshots.

Yes, I'm just saying that NetBeans has troubles parsing stl files of particular version, 5.4 in this case. By the way, are you sure that your project is configured properly? I mean the standard is set to C++11 or C++14. Can you please attach the sample project here?
Comment 7 Otisburg 2017-01-11 01:51:09 UTC
Created attachment 163369 [details]
sample project

(In reply to petrk from comment #6)
> > Just to reiterate, I'm able to compile and run just fine. The error is in the editor/code assistance.  Please see attached screenshots.
> 
> Yes, I'm just saying that NetBeans has troubles parsing stl files of
> particular version, 5.4 in this case. By the way, are you sure that your
> project is configured properly? I mean the standard is set to C++11 or
> C++14. Can you please attach the sample project here?

Under "Project Properties" -> "Build" -> "C++ Compiler" -> "Basic Options", C++ Standard is set to C++14.

The sample project is attached.
Comment 8 petrk 2017-04-03 12:15:27 UTC
Hi, 

Cannot reproduce the bug, even with headers from gcc 5.4. Can you please extract somehow the part which prevents "auto" from being resolved? Or at least attach preprocessed file here (using -E option)?
Comment 9 Otisburg 2017-08-19 06:26:54 UTC
(In reply to petrk from comment #8)
> Hi, 
> 
> Cannot reproduce the bug, even with headers from gcc 5.4. Can you please
> extract somehow the part which prevents "auto" from being resolved? Or at
> least attach preprocessed file here (using -E option)?

I started with a clean install of Netbeans 8.2 to try to reproduce the bug, and at first I was unable to reproduce it.

Unable to reproduce the bug:
At first, I only had the attached sample project opened (see attachments at the top of this bug report page).  With just that project open in Netbeans, if I right click on the project -> Code Assistance -> Reparse Project, then while the project is in the process of being re-parsed, I do notice that the red underline appears, as shown in the screenshot (see first attachment at the top of this bug report page).  However, just before the parsing process completes (i.e. the progress bar at the bottom right of the Netbeans window is almost at 100%), the red underline disappears, and the auto variable in the range based for loop seems to be successfully resolved.  So it seems like resolving that auto variable happens near the end of the parsing process.

Able to reproduce the bug:
However, I was then able to recreate the bug by opening another particular large C++ project that I'm working on, in addition to the attached sample project.  With both projects open, when I again try to re-parse the attached sample project, it starts out doing the same thing in that the red underline appears during parsing, but this time, when the parsing finishes, the red underline doesn't disappear, and Netbeans is unable to resolve the auto variable in the range based for loop.  If I then close that large project, and again re-parse the sample project, then the red underline does disappear as described above (under "Unable to reproduce the bug:"), and the auto variable in the range based for loop gets successfully parsed.

I can't attach that large C++ project because #1 it's big, and #2 it's a project for work.  There seems to be something about having that large project open that prevents the IDE from successfully parsing and resolving auto variables in range based for loops, but I don't know what that 'something' is yet.
Comment 10 Otisburg 2017-08-19 07:44:26 UTC
I've just discovered that the bug can be reproduced by creating any new C++ project (C++ application) in Netbeans.  So if I have two projects open in Netbeans, where one project is the sample project, and the other project is the new default C++ project, when I re-parse the sample project, I see the bug.