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 248908 - C++ Code assistance incorrectly marks "unable to resolve identifier" in two-namespace files with std class members
Summary: C++ Code assistance incorrectly marks "unable to resolve identifier" in two-n...
Status: NEW
Alias: None
Product: editor
Classification: Unclassified
Component: Hints & Annotations (show other bugs)
Version: 8.2
Hardware: PC Windows 10 x64
: P3 normal with 1 vote (vote)
Assignee: petrk
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-26 03:37 UTC by hmunozb
Modified: 2018-01-23 10:40 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Unable to resolve identifier Example (76.77 KB, image/gif)
2017-07-17 03:42 UTC, vijer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description hmunozb 2014-11-26 03:37:47 UTC
Consider the following files:
////////
//b.h
#ifndef B_H
#define B_H
namespace foo{
//optionally stuff
}
namespace std{
//optionally stuff 
}
#endif


//a.h
#ifndef A_H
#define A_H
#include <vector>
#include <unordered_map>
#include "b.h"

using namespace std;

namespace foo{
    class c{
    private:
	vector<int> v;
	unordered_map<int, int > u;
    public:
	c();
	void f();
    };
}
#endif


//a.cpp
#include<iostream>
#include "a.h"

namespace foo{
    c::c(){
	v = vector<int>();
	u = unordered_map<int,int>();
    }
    void c::f(){
	v.push_back(5);

	if( u.empty() )cout << v[0];
    }
}

/////

This compiles and runs correctly given a main function {c cc; cc.f(); return 0;}, of course in a main file including "a.h" and using namespace foo. However, the push_back method of v and the empty method of u are incorrectly underlined red by code assistance with an "Unable to resolve identifier ..." error. This goes away if namespace std {} is commented out from b.h or even replaced by some namespace bar {}

In context of how I encountered this bug, I had an enum class in b.h::foo and tried to write an  std::hash<>() for it in b.h::std so I could use it as a key in the unordered map in a.h::foo. 

I have the following from the IDE Log:

Product Version         = NetBeans IDE 8.0.1 (Build 201408251540) (#b8e35b888b3f)
  Operating System        = Mac OS X version 10.10.1 running on x86_64
  Java; VM; Vendor        = 1.8.0_05; Java HotSpot(TM) 64-Bit Server VM 25.5-b02; Oracle Corporation
  Runtime                 = Java(TM) SE Runtime Environment 1.8.0_05-b13
  Java Home               = /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre
  System Locale; Encoding = en_US (nb); UTF-8
Comment 1 aschwarz1309 2015-01-03 21:19:19 UTC
This issue is not restricted to namespaces. For years netbeans has reported false errors on statements. An example is given below.

Each release seems to report false errors, with some releases more faulty than others. I have reported this issue several times over the last several years. In asperity I ask if there is any way to correct these faulty error? They are distracting and (in their multitude) shield other errors worthy of consideration.


 size_t xstride = 1; // netbeans reports "Unable to resolve identifier xstride"
                     // and no other errors in the file.

art
Comment 2 vijer 2017-06-17 02:52:02 UTC
This continues to be a problem in NetBeans 8.2.

I added a new C++ project: File >> New Project >> C++ >> C++ Application and used the default C++ for create main.

When I open the main.cpp this code is already in the file

int main(int argc, char** argv) {

    return 0;
}


and NetBeans 8,2 highlights main, argc, and argv with red squiggles and says it is "unable to resolve identifier main, etc." Really?

If I add more code like:

    int var1 = 1;

NetBeans 8.2 reports "unable to resolve identifier var1." Really? I just declared it!

As the original post states it is distracting and makes it difficult to see actual errors. I have checked all of the C++ Code Assistance settings and they are valid.  The code compiles without issue.

Please fix this bug.
Comment 3 vijer 2017-07-17 03:42:38 UTC
Created attachment 164776 [details]
Unable to resolve identifier Example

Clean install of Windows 10
Clean install of jdk-8u131-windows-x64
Clean install of cgywin64
Clean install of Netbeans 64

Still get this error on every C++ file
Comment 4 greylander 2017-11-21 22:16:35 UTC
I have been using netbeans for an introductory C programming class.

One of my students has this issue persistently.  So far re-installing, etc., has not resolved the issue.

I and one other student have encountered this briefly, but in both cases simply restarting netbeans cleared it up. I recall a message about updating tools after the restarts.

For the student with the persistent problem, just restarting netbeans obviously is not fixing it. I do not have regular access to the student's laptop to readily do further troubleshooting.

In all cases this has been on Win10x64 systems.

And to clarify:  the compiler has no problem with the source files -- they build and run normally.

It is the editor or a plugin which is intended to detect errors on the fly which is incorrectly flagging all or nearly all symbols as unresolved.

I'll that we're doing C, not C++, but I don't think it makes a difference.
Comment 5 Cube_ 2018-01-23 07:10:46 UTC
This also happens for me, albeit only for vectors.

this sample code reliably reproduces the defect (on my machine):

#include <vector>

int someFunc()
{
    std::vector<int> someVector { 0 };
}

additionally here is a screenshot of the bug in effect https://i.imgur.com/Wtuw88N.png (whether you review said screenshot is at your discretion, naturally - resolution 303x182px)
Comment 6 petrk 2018-01-23 10:40:42 UTC
Unfortunately, it is not possible to fix it now, because C/C++ part has not moved to Apache yet. You can track the progress here: https://cwiki.apache.org/confluence/display/NETBEANS/Apache+Transition