Running into "error: [...] is a c++ extension"

Running into "error: [...] is a c++ extension"

运行之后: g++ --std=c++11 -ansi -pedantic-errors -Wall -o test_database test_database.cpp

我收到以下错误:

./database.h:40:10: error: 'auto' type specifier is a C++11 extension [-Werror,-Wc++11-extensions]
    for (auto x:composerMap_) {
         ^
./database.h:40:16: error: range-based for loop is a C++11 extension [-Werror,-Wc++11-extensions]
    for (auto x:composerMap_) {

但请注意,我已经添加了在许多其他与此类似的 Whosebug 帖子中推荐的“--std=c++11”标志。这对我来说已经浪费了几个小时。我该如何克服这个问题?我在 macOS monterey 12.1 上。以下是有关我使用的 g++ 版本的详细信息:

g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

来自GCC manual

-ansi

In C mode, this is equivalent to -std=c90. In C++ mode, it is equivalent to -std=c++98.

去掉-ansi-std=c++11 -pedantic-errors就够了。

我还建议添加 -Wextra...