I would like to compile a C++ code using Emscripten, where I use some C++11 features. Unfortunately I get an error:
index.cpp:13:18: error: expected expression
vv.push_back({1.5f, 2.f});
^
index.cpp:14:18: error: expected expression
vv.push_back({5.f, 0});
^
index.cpp:15:18: error: expected expression
vv.push_back({1, 1});
^
index.cpp:17:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto& item : vv) {
^
index.cpp:17:20: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for(auto& item : vv) {
I can't understand, why I get this errors. The newest Emscripten and Clang versions are activated using emsdk
.
The code is:
#include<iostream>
#include<vector>
struct AA {
float a;
float b;
};
int main() {
std::vector<AA> vv;
vv.push_back({1.5f, 2.f});
vv.push_back({5.f, 0});
vv.push_back({1, 1});
for(auto& item : vv) {
std::cout << item.a << ' ' << item.b << std::endl;
}
}
I even get a message: LLVM version appears incorrect (seeing "4.0", expected "3.7")
If it is true, it should wotk, because "Clang 3.3 and later implement all of the ISO C++ 2011 standard."
Suggestion: add -std=c++11
to your compiler options.
-Wc++11-extensions
is a flag to add warnings, not to add C++11 support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With