I, too, had this same problem/error message with the same source code using my Mac Studio with M1 based on Apple arm64 silicon.
First, the source code comes from a tutorial: Using Clang in Visual Studio Code.
When I run the code, I get this error for vector<string> msg
:
expected ';' at end of declaration
range-based for loop is a C++11 extension [-Wc++11-extensions]
Second, as @Harry mentioned in a comment for this question:
initializing std::vector with initializer list is supported from c++11 on-wards.
Solution: add a compiler version to tasks.json
that supports vector<string> msg
. For me, I used -std=c++17
to the "args" list to solve the problem. As an FYI, I verified that -std=c++11
also solves the problem. Even -std=c++2b
for the 2023 standard works with the Xcode version 14.2 command line extensions.
So, the default tasks.json
file created for me in the tutorial from code.visualstudio.com was missing any reference to a compiler version directive.
Here is my updated tasks.json
file with the one new element added to the args list:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-std=c++17",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}