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 268419 - Error on string with using std::string
Summary: Error on string with using std::string
Status: VERIFIED FIXED
Alias: None
Product: cnd
Classification: Unclassified
Component: Code Model (show other bugs)
Version: 8.2
Hardware: PC Windows 10 x64
: P2 normal (vote)
Assignee: Vladimir Kvashin
URL:
Keywords:
: 268759 269323 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-10-08 15:49 UTC by antoniocs
Modified: 2016-12-15 09:48 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Using error (63.65 KB, image/png)
2016-10-08 15:49 UTC, antoniocs
Details
Using error2 (15.55 KB, image/png)
2016-10-08 16:58 UTC, antoniocs
Details
screenshot - Unable to resolve identifier string. (119.52 KB, image/png)
2016-10-09 17:00 UTC, Otisburg
Details
std::vector error (9.90 KB, image/png)
2016-10-14 16:01 UTC, antoniocs
Details
vector now works with using namespace std; (9.25 KB, image/png)
2016-10-14 16:02 UTC, antoniocs
Details

Note You need to log in before you can comment on or make changes to this bug.
Description antoniocs 2016-10-08 15:49:23 UTC
Created attachment 162403 [details]
Using error

I have a project that I have created from existing sources.

I have a namespace and inside a class.
In the namespace I have: using std::string;

In the class I have a property of type string: string _window_title;

Netbeans is giving me the following error: "Unable to resolve identifier string"

I also have a line with the following code: this->_window_title.c_str()
Netbeans complains of the following: "Unable to resolve identifier c_str"

The code compiles just fine. I have set the project as c++14.
I the attachment you can see the string issue and how it compiles just fine.

Am I missing something?
Comment 1 soldatov 2016-10-08 16:43:59 UTC
Which GCC you are using? Which tools you are using (MinGW, Cygwin, MSYS2, ...)? Do you see bug in simple cases? For example:


#include <string>

namespace ABC {
    using std::string;
    class A {
    public:
        string s;
    };
};

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

    return 0;
}
Comment 2 antoniocs 2016-10-08 16:58:10 UTC
I am using msys2. 
I can still see the error in the example you gave.

I have created a file named example1.cpp in a project that was created with existing sources and I get the same exact error.
Comment 3 antoniocs 2016-10-08 16:58:32 UTC
Created attachment 162404 [details]
Using error2
Comment 4 antoniocs 2016-10-08 17:00:00 UTC
Forgot to add gcc version: 
gcc -v
Relevant output: gcc version 6.2.0 (Rev2, Built by MSYS2 project)
Comment 5 soldatov 2016-10-08 19:13:46 UTC
Confirmed. Bug can be reproduced with GCC 6.2. Test platform: Ubuntu 16.10 nightly build.
Comment 6 soldatov 2016-10-08 19:35:35 UTC
In modern GCC a 'string' class exists in std::__cxx11 inline namespace and IDE can't find this class in std namespace. In my environment it is a "valid" code:

#include <string>

namespace ABC {
    using std::__cxx11::string;
    class A {
    public:
        string s;
    };
};

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

    return 0;
}
Comment 7 Otisburg 2016-10-09 17:00:10 UTC
Created attachment 162411 [details]
screenshot - Unable to resolve identifier string.
Comment 8 Otisburg 2016-10-09 17:02:35 UTC
Forgot to add comments to previous attachment:

I'm seeing the same thing.  See attachment for a screenshot of a simple example.
Comment 9 Vladimir Kvashin 2016-10-11 12:42:50 UTC
I can not reproduce this on my Ubuntu 12.4 with g++ 4.9.3.
But I can reproduce this on remote Ubunti 16.10 on VirtualBox with the default gcc 6.2.0
Comment 10 Vladimir Kvashin 2016-10-11 13:27:27 UTC
That's because of inlining of the cxx11 namespace into std, see
/usr/include/i386-linux-gnu/c++/6/bits/c++config.h:224

The minimal example that does not involve system headers is as follows:

namespace my_std {

    namespace my_cxx11 {
        template<typename T> class my_basic_string {
        };
        typedef my_basic_string<char> my_string;
    }
    
    inline namespace my_cxx11 { }
    
    class my_std_class {
        my_string str;
    };
}

int main(int argc, char** argv) {
    using my_std::my_string;
    my_string x; // unresolved; but compiles OK
    return 0;
}
Comment 11 Vladimir Kvashin 2016-10-11 13:55:52 UTC
Even more simple example. It seems that the problem is in using directive that refers to an inlined namespace member. Other use cases seem to work well

namespace my_outer {
    inline namespace my_inner {
        class my_class {            
        };
    }
}

void foo() {
    using my_outer::my_class;
    my_class var; // unresolved although compiles OK
}
Comment 12 Vladimir Kvashin 2016-10-11 14:02:26 UTC
That's because of inlining of the cxx11 namespace into std, see
/usr/include/i386-linux-gnu/c++/6/bits/c++config.h:224

The minimal example that does not involve system headers is as follows:

namespace my_std {

    namespace my_cxx11 {
        template<typename T> class my_basic_string {
        };
        typedef my_basic_string<char> my_string;
    }
    
    inline namespace my_cxx11 { }
    
    class my_std_class {
        my_string str;
    };
}

int main(int argc, char** argv) {
    using my_std::my_string;
    my_string x; // unresolved; but compiles OK
    return 0;
}
Comment 13 Vladimir Kvashin 2016-10-11 15:24:55 UTC
fixed in 240a40fdaa36 (enum/release82)
Comment 14 antoniocs 2016-10-12 09:13:14 UTC
Is there a guide on how to get this new version? I normally just get the stable version (currently 8.2)
Comment 15 Vladimir Kvashin 2016-10-12 10:13:15 UTC
I've just pushed change set into cnd-main:
http://hg.netbeans.org/cnd-main/rev/441c2562d11e

This means that it should get into daily build (http://bits.netbeans.org/download/trunk/nightly/latest/) soon (within a day I think).

Also a patch that contains this and other fixes will be created; but the exact time frame for the patch not yet defined.
Comment 16 Quality Engineering 2016-10-13 01:57:45 UTC
Integrated into 'main-silver', will be available in build *201610130002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/441c2562d11e
User: Vladimir Kvashin <vkvashin@netbeans.org>
Log: fixed #268419 - Error on string with using std::string
(transplanted from 240a40fdaa36e7ac5b90718f47fbf3b3ab9b31d6)
Comment 17 antoniocs 2016-10-14 15:40:48 UTC
Hey,

Sorry to keep posting here but is there any way to get the version that has the fix without having to download netbeans with all the options?

Currently I am just using netbeans for c/c++ and for php. I don't need to download the version with 220mb but I do need the version with this fix because something like std::vector is also triggering the error.

I tried looking for a guide but the link:

- http://bits.netbeans.org/dev/nightly/2016-10-14_00-02-33/

Doesn't give me many options. Either I download netbeans with java bundles or I download with everything.

Thanks.
Comment 18 antoniocs 2016-10-14 16:01:06 UTC
Created attachment 162512 [details]
std::vector error
Comment 19 antoniocs 2016-10-14 16:02:04 UTC
Created attachment 162513 [details]
vector now works with using namespace std;
Comment 20 antoniocs 2016-10-14 16:06:01 UTC
Hey,

I just downloaded the latest version:

Product Version: NetBeans IDE Dev (Build 201610140002)
Java: 1.8.0_101; Java HotSpot(TM) 64-Bit Server VM 25.101-b13
Runtime: Java(TM) SE Runtime Environment 1.8.0_101-b13
System: Windows 10 version 10.0 running on amd64; Cp1252; en_GB (nb)

I can now use std::string but I can't use std::vector (and std::string works even if I don't include the <string> header)

I have attached a screenshot 2 screenshots.

The attachment "std::vector error" shows netbeans highlighting an error which is not an error.

The  attachment "vector now works with using namespace std;" shows how adding namespace magically fixes everything. 

Both versions compile just fine by doing:

g++ -Wall -g -std=c++14 -o vec_test vec_test.cpp
Comment 21 antoniocs 2016-10-14 16:20:58 UTC
Here is the code in the screenshot:


#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char** argv) {    
    vector<int> a; //if you add std:: netbeans will highlight it as an error

    for (int i = 0; i < 10; i++) {
        a.push_back(i);
    }
    
    for (int i : a) {
        std::cout << i << " ";
    }
    
    std::cout << std::endl;
    
    return 0;
}
Comment 22 Vladimir Kvashin 2016-10-19 09:30:48 UTC
The root cause is quite different, so I filed a separate issue 268582 in this respect. I'm closing this one as fixed.
Comment 23 Vladimir Kvashin 2016-11-01 10:21:57 UTC
*** Bug 268759 has been marked as a duplicate of this bug. ***
Comment 24 soldatov 2016-12-10 21:59:19 UTC
Code in Comment 10, Comment 11 and Comment 12 has been fixed.
Original problem (Comment 2) is not a fixed.
Comment 25 Alexander Pepin 2016-12-13 15:11:26 UTC
Verified in patch1 build 2016-12-12.
Comment 26 Vladimir Voskresensky 2016-12-14 12:58:49 UTC
*** Bug 269323 has been marked as a duplicate of this bug. ***
Comment 27 soldatov 2016-12-15 09:48:03 UTC
Second testcase has been fixed too in NetBeans 8.2 patch 1.