In XCode clang 11 I get: No template named 'initializer_list' in namespace 'std'

In XCode clang 11 (c++) I get: No template named 'initializer-list' in namespace 'std'
How do I get XCode to work?

When someone on my team executes:
Code Block
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake .. -G Xcode

using XCode 10, and then opens the xcodeproj folder, Xcode starts and everything compiles.

In his project.pbxproj file are:
Code Block
OTHER_CPLUSPLUSFLAGS = "-std=c++11 -pthread -fstrict-aliasing -Wall -Wcast-qual -Wextra -Wformat -Wpedantic -Wswitch-default -Wno-unknown-pragmas
OTHER_LDFLAGS = " -Wl,-search_paths_first -Wl,-headerpad_max_install_names $HEAD/sdsp/metrics/test/build/sws-metrics/Release/libsws-metrics.a";


It does not work for me when I do this using:
_Apple clang version 11.0.0 (clang-1100.0.33.17)
_I get compiler errors:
Code Block
No template named 'initializer_list' in namespace 'std'

and
Code Block
A space is required between consecutive right angle brackets (use '> >')

My OTHER_ variables are blank. I tried setting these to be like his- it didn't help.

In the project I tried all the various options for

Apple Clang - Language

  • C Language Dialect - Compiler Default, c11, gnu11

Apple Clang - Language - C++
  • C Language Dialect - C11 [-std=c++11] (and gnu11 and the 14 and 17's)

  • C Standard Library - Compiler Default, libstdc, libc++

Apple Clang - Warnings - C++
  • Using C11 extensions in earlier versions of C - was No, I also trie Yes

Nothing works.We both create the makefiles from the same folder with:
Code Block
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake .. -G Xcode

I also tried the 3.17.0 cmake I had in homebrew, and after upgrading it to 3.18.1. No difference.
Any idea what to do?

(I have an old XCode10.3, but it won't run- it tries to "install additional components" and fails...)

What am I missing, or is XCode 11 broken?
If I add the line: #include <initializerlist>
XCode seems to accept it.
If I jump to it, it finds it, in the namespace std
But I STILL get the error...

Below are my .h file, followed by a .c file.
On both of the "set" lines which use std::initializer
list,
I see the error: No template named 'initializerlist' in namespace 'std'_
Code Block
#ifndef BOGUS_H
#define BOGUS_H
#include <initializer_list>
#include <string>
namespace STUPID {
  class Bogus {
  public:
    Bogus() = default;
    Bogus(const std::string& filename);
    Bogus(const int argc, char* argv[]);
    void set(const std::string& key, const std::initializer_list<std::string> list);
  };
}
#endif

Code Block
#include "Bogus.h"
namespace STUPID {
  Bogus::Bogus(const std::string& filename) {
  }
  Bogus::Bogus(const int argc, char* argv[]) {
  }
  void Bogus::set(const std::string& key, const std::initializer_list<std::string> list) {
    // do nothing
  }
}


Since you only allow text attachments (and no URLs),
I put an example project on my web site:

ran dy dot strausses dot net slash info slash be

(you changed the 1st 5 letters to stars till I added a space...)
Is it really Bogus.c, not something like Bogus.cpp, Bogus.cc, Bogus.cxx? If it is really Bogus.c, how are you telling Xcode that it is a C++ file?

This works for me on all versions of C++ >= 11:

Code Block
// Bogus.hpp
#include <string>
#include <initializer_list>
#pragma once
namespace Testit
{
class Bogus
{
public:
Bogus() = default;
Bogus(const std::string& _filename) noexcept;
Bogus(int _argc, const char* _argv[]) noexcept;
void set(const std::string& _key,
const std::initializer_list<std::string> list);
};
}


Code Block
// Bogus.cpp
#include "Bogus.hpp"
namespace Testit
{
Bogus::Bogus(const std::string& _filename) noexcept
{
}
Bogus::Bogus(int _argc, const char* _argv[]) noexcept
{
}
void Bogus::set(const std::string& _key, const std::initializer_list<std::string> list)
{
}
}


Code Block
// main.cpp
#include "Bogus.hpp"
int main(int _argc, const char * _argv[])
{
std::initializer_list<std::string> list = {"one","two","three"};
Testit::Bogus bogus(_argc,_argv);
bogus.set("key",list);
return 0;
}




Your C++ language dialect is set to "Compiler Default" in your project after being created by cmake. The default C++ language version is C++ 98, I believe. Changing the C++ language dialect to c++11 build successfully. Also, C++ 98 does not support the ">>" in template definition, that came about in C++ 11 as well.

Not sure your "compiler_flags.cmake" file is being processed successfully. None of the settings defined in the file seem to be set (did a quick look at the Xcode project log to see how the compiler was invoked). You might want to change the "Clang" to "clang++" in your cmake file.

Can't explain about colleague's Xcode 10. Should be the same compiler default. His/her invocation of cmake seems to be doing the right thing.



In XCode clang 11 I get: No template named 'initializer_list' in namespace 'std'
 
 
Q