Compiler flags in our makefiles

Just trying to figure out the history and reasoning behind some of the flags we have - for example, in the math repo we have -Wno-unused-function in the following circumstances:

  • Windows g++ or mingw32-g++
  • OSX g++ or clang++
  • Linux clang++

Why isn’t this flag universal? e.g. why isn’t it also present for Linux g++?

Separately, I’m guessing this flag is in place because we decided we didn’t care about warnings for unused functions? Curious about that too.

Other non-universally declared flags in the math repo I’m curious about:

  • -Wno-unknown-warning-option
  • -Wno-tautological-compare
  • -Wsign-compare
  • -Wno-uninitialized

Would love to make these universal, especially now that our Jenkins setup is getting less homogeneous with the addition of the 16 core Linux box in Ben’s office.

I think @syclik might have answers here but wanted to post here for posterity as well.

In general, not all compilers (or not all versions) accept the same flags. So, having some -Wno flag be universal might generate a warning that the flag was unrecognized. But basically your guesses about why things ended up the way they did is correct.

The flags are often presented to both compilers, but maybe there was some implicit versioning - like that whatever Linux box we were using had an older GCC that didn’t accept some of them? I don’t think this is the case anymore…

The least common denominator up until relatively recently was g+±4.6 for Windows, but we can assume g+±4.9 now. Although I think all recent versions of clang++ would not actually stop if given a GCC-specific flag, they would complain.

The overall history is that Stan used to be one project. That was for what is now Stan, Math, CmdStan, and RStan. RStan always had a separate build process, but Stan, Math, and CmdStan shared one set of makefiles that worked cross platform. We relied on make to do a few things for us: 1) build target for bin/stanc; once upon a time on Windows, we had MSVC build bin/stanc and g++ build a Stan program, 2) build and execute tests; we now leave the makefile to build tests and use the python script to execute it which has simplified the makefiles a lot, and 3) build Stan program executables.

For CmdStan, Stan, and Math (and for a time, RStan, but not anymore), we’ve made it a priority to have 0 compiler warnings. Early on, we’d get a lot of activity on the users list with every compiler warning. We (mostly Bob and I), got the warnings down to 0 and we’ve been maintaining that.

These flags are what we added to kill some of the warnings that were difficult to fix in code. For example, the -Wno-uninitialized flag pops up a lot in the generated C++ code.

And of course, a lot of these flags were added without much thought with updated versions of different compilers on Travis CI or sometimes on Jenkins.