I have gcc.exe on my computer. May I please know how to find version of gcc.exe I have.
May I please know what is the command line to compile using C++ 17 features?
Don't bother with GCC 7.1 just yet, as far as C++17 is concerned.
It accepts a -std=c++17 option, but it still hasn't got something as fundamental as evaluation of expressions right.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int foo( int i )
{
// C++17 specifies :
// In every simple assignment expression E1=E2
// and every compound assignment expression E1@=E2,
// every value computation and side-effect of E2 is sequenced before
// every value computation and side effect of E1
// http://en.cppreference.com/w/cpp/language/eval_order
// [x86-64 gcc 7.1 with -std=c++17 -Wall -Wextra -Werror -pedantic-errors -O3 ]
// error: operation on 'i' may be undefined
i = ++i - 1 ;
return i ;
}
Examples of code with undefined behavior are a = a++;, a[n] = b[n++] and a[i++] = i;. Some more complicated cases are not diagnosed by this option, and it may give an occasional false positive result, but in general it has been found fairly effective at detecting this sort of problem in programs.
The C++17 standard will define the order of evaluation of operands in more cases: in particular it requires that the right-hand side of an assignment be evaluated before the left-hand side, so the above examples are no longer undefined. But this warning will still warn about them, to help people avoid writing code that is undefined in C and earlier revisions of C++.
> I guess one wouldn't want to play Russian Roulette with -Wnosequence-point ;
> there are still some expressions that remain unspecified
And there are also expressions that engender undefined behaviour in C++17. int i = 7 ; i = ++i + i++ ; // undefined behaviour, even in C++17
I guess the only viable option is to compile with -Wsequence-point and then examine each order of evaluation warning to figure out if it is a spurious warning.