0

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
Solver
  • 57
  • 7

1 Answers1

1

From GCC manual:

-ansi

In 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...

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • This seems to be fixing it for me. Will mark as accepted answer after the required 5 more minutes has elapsed. Thank you! – Solver May 17 '22 at 21:11