5

I am playing with unique_ptr. In my last post people helped me compiling a program that used this pointer by specifying the -std=c++0x during compilation. Now i was wondering if there is any way to instruct eclipse to consider c++11 while auto-completing?
unique_ptr is not coming in the list of std:: namespace, nor I can find the methods (reset, move...) associated with a unique_ptr.

Thank you vahid

Community
  • 1
  • 1
rahman
  • 4,820
  • 16
  • 52
  • 86
  • I know someone knows all 30 steps to get it right, but I would switch to kdevelop and enable autocomplete feature ;) – BЈовић Mar 19 '12 at 08:30
  • 2
    Does the advice in the last comment on [this bug](https://bugs.eclipse.org/bugs/show_bug.cgi?id=314014) help? I don't use Eclipse, So I cannot try it out. – Alok Save Mar 19 '12 at 08:30
  • @Als No it didn't work, but tanx. FYI,I opened project properties->C/C++ Build->Discovery Options->GCC C++ Compiler : in Compiler Invokation arguments I added -std=c++0x but nothing worked. – rahman Mar 19 '12 at 08:41
  • @VJovic cant do that. At least not now. – rahman Mar 19 '12 at 08:42
  • The solution which @AlokSave provides worked for me! – KiaMorot Apr 26 '13 at 14:09

2 Answers2

3

The "memory" header (probably found at /usr/include/c++/4.9/memory) only includes "unique_ptr.h" and "shared_ptr.h" (probably found at /usr/include/c++/4.9/bits/unique_ptr.h and /usr/include/c++/4.9/bits/shared_ptr.h) if the macro "__cplusplus" is equal or greather than "201103L". Check memory.h for yourself to see the "#if" preprocessor condition there, at line 69 (or search for the string "#if __cplusplus >= 201103L").

As others mentioned, compiling with "-std=c++0x" or later c++ standards (-std=c++11 or -std=c++14) solves the compilation errors, but not the eclipse indexing and autocomplete problem.

To solve the eclipse indexing issue I added the "__cplusplus" Preprocessor Macro to the project build properties, with the value "201103L", and afterwards I refreshed the index;

To add the preprocessor macro:

"right click the project on project explorer" >> properties >> C/C++ General >> Preprocessor Includes >> Entries >> GNU C++ >> CDT User Settings Entries >> Add... >> Preprocessor Macro;

Then entry a macro with name "__cplusplus" and value "201103L";

Afterwards, to refresh the index, do:

"right click project on project explorer" >> Index >> Rebuild;

Ps.: I was using gcc 4.9.2 and eclipse Luna (4.4.2), on ubuntu 15.04 64bits

gnumaru
  • 151
  • 1
  • 4
1

I guess you should add __GXX_EXPERIMENTAL_CXX0X__ definition to your "Paths and Symbols" in Eclipse. See also this question GNU C++ how to check when -std=c++0x is in effect? and the same question Eclipse indexer can't resolve shared_ptr for shared_ptr.

Community
  • 1
  • 1
ks1322
  • 33,961
  • 14
  • 109
  • 164
  • couldn't do it. Is it possible someone more experienced try this? – rahman Mar 19 '12 at 08:47
  • @rahman, look the [same question](http://stackoverflow.com/q/8312854/72178) for `shared_ptr`, OP reported that it worked. – ks1322 Mar 19 '12 at 08:54
  • I am on Eclipse Juno and while setting that symbol does work for recognizing std::unique_ptr, the indexer flags any use of std::move with a unique_ptr with an "invalid argument" error. – Hans Dec 05 '12 at 00:07
  • 1
    @Hans: there is a new way to do it in Juno. You should add `-std=c++0x` in Discovery options. See these links for detailed description: [CDT does not recognize C++11 features](http://wiki.eclipse.org/CDT/User/FAQ#CDT_does_not_recognize_C.2B.2B11_features), [eclipse forum](http://www.eclipse.org/forums/index.php/mv/msg/373462/909018/#msg_909018) – ks1322 Dec 05 '12 at 07:55
  • No dice, neither adding the flag to the discovery options or the source navigation prevents compilable code from being flagged as having an error. – Hans Dec 05 '12 at 18:27