'Running into "error: [...] is a c++ extension" [duplicate]
After running:
g++ --std=c++11 -ansi -pedantic-errors -Wall -o test_database test_database.cpp
I am receiving the following errors:
./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_) {
Yet note that I have already added the '--std=c++11' flag recommended in many other stackoverflow posts similar to this one. This has wasted several hours for me. How do I get past this? I am on macOS monterey 12.1. Here are details about the version of g++ I am using:
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
Solution 1:[1]
From GCC manual:
-ansiIn C mode, this is equivalent to
-std=c90. In C++ mode, it is equivalent to-std=c++98.
Remove -ansi, just -std=c++11 -pedantic-errors is enough.
I also suggest adding -Wextra...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HolyBlackCat |
