Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading