0

I'm coming from a Java background and we learned to setup tests for the used java version when working with others, so everyne is using the same and to prevent conflicts.

Is there a way to test for the used standard? Likewise for language features you agreed on not using? Do you do this with a unit test?

Halfdan
  • 21
  • 1
  • You can add a `static_assert` somewhere in your code, and check the version against that. It will cause an error during compilation if it does not match. – ChrisMM Nov 10 '22 at 19:23
  • You have a unit test that says `assert(java.version() == "1.8")`? What feature of your software is that testing? If I want to run your code on Java 12 (which hopefully is backward compatible if your code is written well), then that test is going to fail. – Silvio Mayolo Nov 10 '22 at 19:23
  • There's a significant difference between the two languages. Java code is all interpreted by a runtime -- a given jar might be executed by very different JVM versions, so you need to check. With C++, that's not true. You will specify the std version at COMPILE time, but after it's compiled, you don't care. – Tim Roberts Nov 10 '22 at 19:24
  • 2
    Stage 1 try and agree on the tool-chain and it's version. Stage 2 try and agree on the C++ Standard Version. Stage 3 setup auto builds that uses the above. – Richard Critten Nov 10 '22 at 19:27
  • 2
    I wouldn't bother. Just document what compilers you want to support, set up CI with the compilers you want to support, and reject PRs if the CI fails. Writing a test for this isn't easy: there isn't a single "standard version" you can check, you have to check versions of each compiler you want to support, in a compiler-specific manner. – HolyBlackCat Nov 10 '22 at 19:29
  • This kind of check makes little sense, since basically no compiler implements everything that's in the standard in one go. E.g. look at this "beauty" here: https://en.cppreference.com/w/cpp/compiler_support There are limited checks that are possible though, but usually you'll just compile everything and if the compiler complains, you'll have to figure out why. As for analyzing for features are not used: You probably need a code analyzer for this. – fabian Nov 10 '22 at 19:31

0 Answers0