Success enum constant in Eigen clashes with macro in X11 header file
Submitted by Jitse Niesen
Assigned to Nobody
Link to original bugzilla bug (#253)
Version: 3.0
Description
This issue is discussed on the mailing list in the thread "eigen3 migration" started 13 April, see http://thread.gmane.org/gmane.comp.lib.eigen/1941 . A summary of the discussion follows.
The problem is that the X11 header file X.h include the following macro:
#define Success 0
If this header file is included before Eigen/Core, then the following definition fails to compile:
enum ComputationInfo {
Success = 0,
NumericalIssue = 1,
NoConvergence = 2
};
Furthermore, the resulting error message is apparently rather puzzling.
Possible solutions:
-
Rename Success in Eigen to something else, say SuccessfulComputation. This does however break all Eigen3 user code which uses this constant.
-
Do nothing, and have the user resolve the problem. For instance, the user could #undef Success before the #include <Eigen/Core> if they are not using X.h's Success.
We could make the error message a bit easier to understand with things like
#ifdef Success
#error "Success macro defined by some header file, possibly X.h"
#endif
- Rhys suggested the following: Would something goofy like
enum ComputationInfo {
#ifndef Success
Success = 0,
#elif Success == 0
undef Success
Success = 0,
define Success 0
#else
error "Success #defined with non-zero value"
#endif
NumericalIssue = 1,
NoConvergence = 2
};
work? This works around any preceding '#define Success 0' macro by
'pushing/popping' its definition. In the end, the token 'Success' will still
be macro expanded but ComputationInfo's enum will contain an entry for the
literal as well. Finally, it loudly breaks if someone uses the wholly
incompatible '#define Success 1'.