-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor and centralize compiler detection #2094
Comments
How do you envision this to happen? I only see it going as a giant chain of if/else. I currently pulled together a list of all the defines for all the compilers. Not sure if we should go about this trying to do macros for each compiler to ignore warnings per file or do we want global compiler configuration? Just really wanted to get a little more detail about your thoughts on this. |
@LinuxDevon Yeah, the detection is going to be a big set of defined macros check, the idea is to do that somewhere centrally, so that when Catch2 needs to suppress GCC-specific warning, we can write something like #if defined(CATCH_COMPILER_GCC)
// suppress
#endif rather than iteratively having to stop different compilers from going into the same block, the way it is now, which can lead to this sort of code in multiple places #if defined(__GNUC__) && !defined(__clang__) && !defined(_ICC) |
@horenmar Hi.
|
I hadn't gotten around to this so that was my bad... that was my thought was that as you described. Setup a macro name that for each compiler. You probably don't need the namespace catch {
#define COMPILER_GCC ...
}
// Would read like this as long as you are in the namespace
#if defined(COMPILER_GCC) ... I found this list and had planned to write them for each: https://sourceforge.net/p/predef/wiki/Compilers/ |
As explained in this question |
@HoseynHeydari I don't need a special macro per version, just per compiler. The goal is to replace these checks #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ < 10
#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ < 9
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5 with ones looking like this #if defined(CATCH_COMPILER_GCC) && __GNUC__ < 10
#if defined(CATCH_COMPILER_GCC) && __GNUC__ < 9
#if defined(CATCH_COMPILER_GCC) && __GNUC__ <= 5 |
@LinuxDevon preprocessor macros are not bound by namespaces, or even C++ language structure. That's why their names are prefixed, because that essentially namespaces them per project. |
clang, MSVC and MINGW32. (see catchorg#2094)
CATCH_COMPILER_CLANG macro. (see catchorg#2094)
Currently Catch2 detects compilers ad-hoc, at the place where the code needs to be compiler-specific. This brings a lot of trouble with more obscure compilers, because compilers like to masquerade for different compilers, such as Clang defining GCC-version macros, ICC defining both, IBM XL self-reporting as Clang, and so on. Because compiler-specific sections of code are often indeed compiler-specific, not detecting compilers properly can be a problem, e.g. Clang will complain that it found unknown pragma if we try to disable GCC-specific warning without checking that Clang is not used.
The solution is to perform more rigorous compiler detection, and centralize it, so that updates don't have to be done in multiple places.
The text was updated successfully, but these errors were encountered: