Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368589 - CDT cannot parse make_shared<> from <memory> in C++0x mode
Summary: CDT cannot parse make_shared<> from <memory> in C++0x mode
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: Sergey Prigogin CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on: 327297
Blocks:
  Show dependency tree
 
Reported: 2012-01-13 15:51 EST by Matt Hargett CLA
Modified: 2012-05-17 14:23 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Hargett CLA 2012-01-13 15:51:26 EST
Build Identifier: Build id: 20111215-0110 (CDT Version: 8.1.0.201201101828)

After adding -std=c++0x (or -std=c++11, in the case of GCC 4.7 trunk) to the Discovery Scanner, I am still getting an error ("Symbol 'make_shared' could not be resolved) on any line that mentions make_shared:
#include <memory>
#include <string>

int main(void) {
    auto bob = std::make_shared<std::string>("bob");
    return bob->length();
}

This compiled fine for me locally with g++ 4.6 and 4.7 (trunk), with no warnings.

I've been getting this codebase to be free of errors from the CDT parser and CODAN, and this is a stumbling block.

Reproducible: Always
Comment 1 Markus Schorn CLA 2012-01-16 02:35:43 EST
Works for me using g++ 4.5, most likely the header uses a c++11 feature we don't yet support.
Comment 2 Nathan Ridge CLA 2012-01-16 03:05:22 EST
Since CDT doesn't support all C++11 features in GCC 4.6 and 4.7, it can't accurately parse the standard library headers of those compilers. What I do is install GCC 4.5 on the machine as well, and get CDT to look at the 4.5 headers instead of the 4.6 or 4.7 ones.

One way to do this is to go to Project Properties -> C/++ Build -> Discovery Options, and change the "Compiler invocation command" from g++ to g++-4.5. Then "Clear" the discovered entries and rebuild the project to get CDT to re-acquire them. You can verify in C/C++ General -> Paths and Symbols (Symbols tab) that CDT discarded the 4.6/4.7 headers and picked up the 4.5 ones.
Comment 3 Nathan Ridge CLA 2012-01-16 03:12:56 EST
Note however that if you do this, then CDT won't be able to handle range-based for loops correctly, because the std::begin and std::end functions that are implicitly used by the range-based for loop are not present in the 4.5 headers (they were introduced in 4.6). You can work around *that* too, by copying the 4.5 library's <iterator> file to some folder in your Eclipse include path, and pasting the std::begin and std::end function definitions from the 4.6 version (they are in <bits/range_access.h>) into there.

Hopefully, the Juno version of CDT will have full support for C++11 features used in GCC 4.6, and then these workarounds won't be necessary any more.