Skip to content

Commit 922d505

Browse files
committed
Fix compilation failure for asynStatus in clang 17
After installing a new clang under MacOS: c++ --version Apple clang version 17.0.0 (clang-1700.6.3.2) Target: x86_64-apple-darwin24.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin ---------------- the compilation of a motor driver failed: c++ -DUNIX -Ddarwin -O3 -g -Wall -arch x86_64 -fno-common -fPIC -I. -I../O.Common -I. -I. -I.. -I.../epics/modules/motor/include/compiler/clang -I.../epics/modules/motor/include/os/Darwin -I.../epics/modules/motor/include -I.../epics/modules/motor/include -I.../epics/base/../modules/asyn/include -I.../epics/base/include/compiler/clang -I.../epics/base/include/os/Darwin -I.../epics/base/include -c ../smarActMCS2MotorDriver.cpp ../smarActMCS2MotorDriver.cpp:147:10: error: integer value 8 is outside the valid range of values [0, 7] for the enumeration type 'asynStatus' [-Wenum-constexpr-conversion] 147 | case asynParamWrongType: | ^ [snip] 3 errors generated. ---------------- Problem: Both asynManager and asynPortDriver are using the same enum for different things: asynManager uses the "basic" definitions asynSuccess..asynDisabled and asynPortdriver needs asynParamAlreadyExists and friends for the parameter interface. However, all of the defintions are "public" and can be used in derived classes. Extendig an enum like done before is not allowed in C++, and the clang developers chose to make it an error. And probably other compilers will be more strict in the future as well. Possible solutions: a) One c-stylish way would be to define asynStatus as "int" and use #defines for all the values. b) Split asynStatus into 2 definitions: asynStatusManager and asynStatusDriver c) Define all values used in asyn at one place. a) seems less attractive, since we would loose the ability to let the compiler check enums. b) Seems less attractive since it would break a lot of existing code and force it to be changed to make sense. Or add a lot of #ifndef EPICS_ASYN_SPLIT_STATUS legacey handling. c) Seems to be the least invasive change. Solution: Define all possible values for asynStatus in asynDriver.h Enhance asynManager::strStatus() to handle all new enum values.
1 parent e2a281e commit 922d505

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

asyn/asynDriver/asynDriver.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,19 @@ extern "C" {
4646

4747

4848
typedef enum {
49-
asynSuccess,asynTimeout,asynOverflow,asynError,asynDisconnected,asynDisabled
49+
asynSuccess,
50+
asynTimeout,
51+
asynOverflow,
52+
asynError,
53+
asynDisconnected,
54+
asynDisabled,
55+
/* Values used for the param interface */
56+
asynParamAlreadyExists,
57+
asynParamNotFound,
58+
asynParamWrongType,
59+
asynParamBadIndex,
60+
asynParamUndefined,
61+
asynParamInvalidList
5062
}asynStatus;
5163

5264
typedef enum {

asyn/asynDriver/asynManager.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,6 +3211,12 @@ static const char *strStatus(asynStatus status)
32113211
case asynError: return "asynError";
32123212
case asynDisconnected: return "asynDisconnected";
32133213
case asynDisabled: return "asynDisabled";
3214+
case asynParamAlreadyExists: return "asynParamAlreadyExists";
3215+
case asynParamNotFound: return "asynParamNotFound";
3216+
case asynParamWrongType: return "asynParamWrongType";
3217+
case asynParamBadIndex: return "asynParamBadIndex";
3218+
case asynParamUndefined: return "asynParamUndefined";
3219+
case asynParamInvalidList: return "asynParamInvalidList";
32143220
}
32153221

32163222
return "asyn????";

asyn/asynPortDriver/paramErrors.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,4 @@
1010

1111
#include <asynDriver.h>
1212

13-
/* Extend asynManager error list. We should have a way of knowing what the last error in asyn is */
14-
#define asynParamAlreadyExists (asynStatus)(asynDisabled + 1)
15-
#define asynParamNotFound (asynStatus)(asynDisabled + 2)
16-
#define asynParamWrongType (asynStatus)(asynDisabled + 3)
17-
#define asynParamBadIndex (asynStatus)(asynDisabled + 4)
18-
#define asynParamUndefined (asynStatus)(asynDisabled + 5)
19-
#define asynParamInvalidList (asynStatus)(asynDisabled + 6)
20-
21-
2213
#endif /* ASYNPORTDRIVERERRORSTATES_H_ */

0 commit comments

Comments
 (0)