The title is quite clear, is there a way to disable every single non-standard feature of gcc (extension) when compiling some C++ code. I've previously always used -pedantic-errors alongside -Wall and -Wextra, the first according to the gcc man page does the following
Give an error whenever the base standard (see -Wpedantic) requires a diagnostic, in some
equivalent to -Werror=pedantic, since there are errors enabled by this option and not
particular library's limitations. However, if -Wpedantic is used with -Wformat, warnings
made into an error by -pedantic-errors.
-Wall or -Wpedantic.
As a result it disables practically all extensions that aren't standard conforming, however. I was rather shooked that the following code compiles with gcc
void foo(std::vector<auto>) { ... }
with the -std=c++20 flag, if we bump it down to -std=c++17 we receive an error message prompting the use of -std=c++20 as it's a "c++20 feature". However neither clang or msvc is willing to compile this. After some further research I was notified of the following
This is a GCC extension and accepted by design.
Which is rather upsetting as even the safe-guards of -pedantic-errors, -Wall and -Wextra didn't pick this up, which leads me to question what other extensions might be silently passed through by gcc. Thus the question comes; is there any way to disable exactly every gcc extension?
Edit: From the comment section of How to disable GNU C extensions?
You cannot
I'm building software for an embedded system that only has a cross compiler for -std=c++98. We want to send data encoded via protobuf 2 to a server. Unfortunately protobuf now requires C++11.
In https://github.com/protocolbuffers/protobuf/issues/2780 it's suggested that "We may create a branch that works for C++98. The branch will only accept bug fixes, but not new features, optimization, etc"
https://github.com/protocolbuffers/protobuf/issues/3492 "Code should compile with --std=c++03 before we switch to c++11 only" has been closed, but I can't find the corresponding commit.
I've tried to build a few versions with -std=c++98 and -std=c++03 but always get "error: use of undeclared identifier 'va_copy'" which is specific to c++11 and later.
Can anyone advise which version (if any) builds with -std=c++98 or -std=c++03?
If this isn't possible I could fall back on https://github.com/nanopb/nanopb which is an ANSI C implementation.
Try using v 3.5.0. The release after 3.5.0 has a strict C++11 requirement, 3.5.0 shouldn't have this.
I'm trying to create a native library in C++, which I can use in Android.
I've created a project in Visual Studio 2017: Dynamic Shared Library (Android), and added my cpp code.
Though some of the code is running C++11, and I'd really like to keep it that way.
When I compile, I get the error:
This file requires compiler and library support for the ISO C++ 2011 standard.
This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
So I first tried going to Project->Properties->C/C++->Language->C++ Language Standard, and set the options as following:
'
When I compile now, I get exactly the same error. So I tried manually adding the -std=c++11 flag under additional options, though still getting the error.
Why is the compiler not willing to compile using the ++11 standard, and what can I do to fix this? I know it's experimental, but it should at least try to compile.
Best regards
The problem was solved, when I changed the settings to be for All Platforms, and not just ARM.
I am using OMNET 4.4. When OMNET compiles it says that
this file requires compiler and library support for the ISO c++ 2011 standard. This support is currently experimental and must be enabled with -std=c++11 or -gnu=c++11 compiler options.
Also following error appears:
/veins/modules/application/traci/TraCITestApp.h:78:36: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
I am using windows 10 and I could not find solution to it in internet .
Can anyone help me with some information ?
First, this warning is not coming up from the build of OMNeT++, but from the build of Veins. It is not the same. OMNeT++ 4.4 builds without C++11 support fine, but it seems that recent versions of Veins may need it. However again, this is a warning. OMNeT++ 4.6 and later can be configured with the -std=c++11.
You may need to update your compiler, too as any recent compiler fully supports c++11 since at least 3 years.
Is there a website I can go to to run C++ code online? I have seen a few compilers, but is there one that can also receive input from cin? I want one that can basically host a C++ .exe online, and even more preferable is if it is like the VC++ platform.
You may want to give rextester a try. Currently g++ 4.7.2 with boost libraries and ability to supply compiler args.
Edit
Visual C++ is also supported now.
http://ideone.com/ Can compile several languages, and supports stdin
Yes, Ideone can do that. It's possible to specify stdin there.
Edit: Microsoft's online compiler seems to no longer be active :(
Microsoft research have made an online version of Visual C++ here: http://webcompiler.cloudapp.net/.
It (currently?) only compiles the code and does not run it so you won't be able to check cin though :(
Running code is now supported.
Currently the best online tools seem to be
Special Online Compilers
https://cppinsights.io shows, how C++ introduces conversions, etc. and interprets the source code (current clang based)
https://godbolt.org compare C++ compilers, show disassembly, run (many current compilers including Microsoft VCC and embedded compilers)
http://quick-bench.com create and compare benchmarks (current g++ and clang)
https://www.onlinegdb.com, includes gdb debugger (g++ 7.4.0)
Online Compilers that let you set compile flags
https://wandbox.org (current g++ and clang)
http://coliru.stacked-crooked.com (g++ 9.2.0)
https://repl.it/languages/cpp11 (clang 7.0.0)
https://www.tutorialspoint.com/compile_cpp11_online.php = codingground (g++ 7.1.1)
https://tio.run/#cpp-clang (g++ 8.3.1 and clang 7.0.1)
https://rextester.com/l/cpp_online_compiler_gcc (g++ 7.4.0, clang 6.0.0, VS C++ 2015 Update 1)
Online Compilers that do not let you set compile flags
https://www.jdoodle.com (g++ 9.2.0)
https://www.codechef.com/ide (g++ 9.1.0)
https://ideone.com (g++ 8.3.0 and clang 8.0.0)
https://paiza.io (clang 8.0.0)
https://www.codiva.io/c (clang 7.1.0)
https://code.labstack.com/cpp (g++ 8.3.0)
All listed compilers support C++17 code
Perhaps the following site is what you're aiming for: http://codepad.org/
There is Wandbox.org, which offers GCC and Clang to its latest versions (as of Nov 2018). It has stdin.
I wouldn't say it's a VC++ platform though.
TutorialsPoint's C++ Coding Ground lets you save and compile multiple source files at a time, which can be useful at times, and gives you a GNU bash console to play around with. It's not as convenient for sharing code as sites like Ideone, however.
[Note: While it only has links to C++, C++0x, and C++11 environments, you can compile code for C++14 by specifying the compiler option -std=c++1y. I'm not sure if it has any experimental C++17 support, however.]
repl.it can compile, run, and execute C++ and C++11. It's also interactive and you can ask for user input in realtime.