I'm using Apple Clang to build a C++ project from the terminal. The following lines are printed when building the project:
-- The C compiler identification is AppleClang 15.0.0.15000100
-- The CXX compiler identification is AppleClang 15.0.0.15000100
"clang --version" and "gcc --version" commands show me the following:
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.3.0
Thread model: posix
The next function, while valid with other compilers, displays an error for Apple Clang:
std::vector<char> read_file() {
return {};
}
error: non-aggregate type 'std::vector<char>' cannot be initialized with an initializer list return {};
My questions:
- Am I on the latest Apple Clang version?
- If not, how can I upgrade to it? So far, I've tried:
"xcode-select --install" command, the result:
xcode-select: note: Command line tools are already installed. Use "Software Update" in System Settings or the softwareupdate command line interface to install updates
"softwareupdate -l" command, the result:
Software Update Tool
Finding available software
No new software available.
The installed XCode version on my MacBook is 15.2
I suspect that you are not passing a -std=c++11
(or newer) flag. clang++ defaults to C++98. This style of initialiser list was added in C++11. It likely works on other compilers because they default to a newer C++ version. Apple Clang has good support for newer versions but they have chosen not to make them the default.