In the following code a function is declared/defined as int setYear(int year_h){year = year_h;} (instead of void setYear(...), leading to run-time crash in gcc 8 AND with the flag -O[X] only.
Specific questions:
- What have changed in gcc 8, as it worked in gcc 7 ?
- Which flags can I use (if any) to generate a compilation error (rather than a warning) in gcc8 ?
main.cpp:
#include <iostream>
using namespace std;
int year = 2000;
int setYear(int year_h){year = year_h;}
int main()
{
    cout << "Hello World!" << endl;
    setYear(2019);
    cout << "Year: " << year << endl;
    return 0;
}
Run-time crash with:
g++-8 -O2  -o main main.cpp
./main
Hello World!
Hello World!
Segmentation fault (core dumped)
Works with:
g++-7 -O2  -o main main.cpp
or
g++-8 -o main main.cpp
EDIT: The question Omitting return statement in C++ answers my second question, but not the first one (on the difference between gcc 7 and gcc 8).
 
    