0

It seems that std::deque does not allow to use it in a recursive way with clang on osx when not using libstdc++ (10.9+ target)

#include <deque>

struct node { std::deque<node> childs; };

int main() {
    node n;
}

This simple code compile with clang only if I set MACOS_DEPLOYMENT_TARGET=10.8 (because the clang compiler links with libstdc++) but it gives a lot of errors if I try to compile with libc++ (default c++ target on 10.9+), while with gcc 4/5 it works without problems...

It's a compiler bug or the standard does not allow this? It's seems a quite obvious use of a container...

gabry
  • 1,370
  • 11
  • 26

1 Answers1

1

In general, you should not expect this code to compile. To be sure that it compiles with any standard-compliant compiler you must use an extra level of indirection in one of the following or similar ways:

  1. struct node { std::deque<node> *children; };
  2. struct node { std::unique_ptr<std::deque<node>> children; };
  3. struct node { std::deque<node*> children; };
Leon
  • 31,443
  • 4
  • 72
  • 97