0

On MAC OSX, I am trying to compile the following code

#include <list>

int main()
{
    std::list<int>::iterator it(0);
    return 0;
}

When I run g++ a.cpp -o a I get

a.cpp:5:27: error: calling a private constructor of class
      'std::__1::__list_iterator<int, void *>'
        std::list<int>::iterator it(0);
                                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/list:254:14: note: 
      implicitly declared private here
    explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}

My end goal is to compile this C++ code.


Edit

Is that really gcc? MacOS likes to alias gcc to clang

I think you're right!

$g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

See if this solves your problem (I don't know why clang rejects that standard library implementation's std::list).

mmhh... not really yet. My PATH is

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin

and which gcc indicate indicates /usr/local/bin/gcc. I might not fully understand the other answer though.

Remi.b
  • 17,389
  • 28
  • 87
  • 168
  • 5
    Is that really gcc? MacOS likes to alias gcc to clang. – Rakete1111 Mar 02 '18 at 18:49
  • @Rakete1111 Yes, I think it is clang. See edit – Remi.b Mar 02 '18 at 18:52
  • Knew it. See if [this](https://apple.stackexchange.com/questions/245891/installed-gcc-with-homebrew-now-how-to-use-that-gcc-instead-of-clang) solves your problem (I don't know why clang rejects that standard library implementation's `std::list`). – Rakete1111 Mar 02 '18 at 18:53
  • It's unlikely that anyone will want to download an entire project off sourceforge and try to build it, in order to reproduce your compilation error. You should take the time to prepare a [mcve] of your compilation error that any can reproduce simply by copy-pasting the small chunk of code from your question, and compiling it themselves. – Sam Varshavchik Mar 02 '18 at 18:54
  • @SamVarshavchik Thanks for advice. I made a minimal reproducible example. – Remi.b Mar 02 '18 at 19:09
  • @Rakete1111 `g++-4.8` which does not use clang made it. You nailed the issue direclty. Do you want to make it an answer? Thanks – Remi.b Mar 02 '18 at 19:24
  • 1
    Sure, I am voting to close as duplicate. Thanks a lot! – Remi.b Mar 02 '18 at 19:26
  • Why are you using `std::list::iterator it(0);` instead of `std::list::iterator it;`? – Eljay Mar 02 '18 at 19:28
  • @Eljay My goal was to reproduce a compilation error that I get when I am trying to compile [this code](https://sourceforge.net/projects/nemo2/files/Nemo/2.3.46/). – Remi.b Mar 02 '18 at 19:29
  • @Remi.b • What file and line number in Nemo 2.3.46 is causing the compilation error? – Eljay Mar 02 '18 at 22:47
  • The error was `_genITER(0)` (in the initializer list) at line 801 of the file LCEmisc.cc. (Note that my problem is solved now). Thanks – Remi.b Mar 02 '18 at 22:52
  • 1
    @Remi.b • ahh, I see `_genITER(0)` is bad code, they should have written `_genITER{}`. – Eljay Mar 02 '18 at 23:12

0 Answers0