Skip to content

Commit

Permalink
Cast a macro argument to int to fix a C++20 error. (#958)
Browse files Browse the repository at this point in the history
C++ 20 errors for me on several expansions of the `KHR_DFDSETVAL`
macro because it attempts to bitwise-and two different types of enums.
For example:
```
/home/conscat/vulkan-experiments/KTX-Software/lib/basis_encode.cpp:256:5: error: invalid bitwise operation between different enumeration types ('_khr_df_vendorid_e' and '_khr_df_mask_e')
  256 |     KHR_DFDSETVAL(nbdb, VENDORID, KHR_DF_VENDORID_KHRONOS);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/conscat/vulkan-experiments/KTX-Software/include/KHR/khr_df.h:109:13: note: expanded from macro 'KHR_DFDSETVAL'
  109 |     (((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X)))
      |       ~~~~~ ^ ~~~~~~~~~~~~~~~~~~~
```
This PR simply casts the value to an int inside of the macro.
  • Loading branch information
Cons-Cat authored Nov 28, 2024
1 parent bd8ae31 commit 60c3689
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/KHR/khr_df.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ typedef enum _khr_df_mask_e {
((BDB)[KHR_DF_WORD_ ## X] = \
((BDB)[KHR_DF_WORD_ ## X] & \
~((KHR_DF_MASK_ ## X) << (KHR_DF_SHIFT_ ## X))) | \
(((val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X)))
(((int)(val) & (KHR_DF_MASK_ ## X)) << (KHR_DF_SHIFT_ ## X)))

/* Offsets relative to the start of a sample */
typedef enum _khr_df_sampleword_e {
Expand Down

0 comments on commit 60c3689

Please sign in to comment.