Commit 922d505
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
50 | 62 | | |
51 | 63 | | |
52 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3211 | 3211 | | |
3212 | 3212 | | |
3213 | 3213 | | |
| 3214 | + | |
| 3215 | + | |
| 3216 | + | |
| 3217 | + | |
| 3218 | + | |
| 3219 | + | |
3214 | 3220 | | |
3215 | 3221 | | |
3216 | 3222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 13 | | |
0 commit comments