Fix gcc-8 build of common/arch/sdl/key.cpp

gcc-7 allows `constexpr auto X = std::initializer_list<unsigned>{A1, A2,
...};`.  gcc-8 rejects it:

```
common/arch/sdl/key.cpp:583:105: error: 'const std::initializer_list<const SDL_Scancode>{((const SDL_Scancode*)(&<anonymous>)), 3}' is not a constant expression
  constexpr auto sticky_keys = {SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_NUMLOCKCLEAR};
```

Switch to a macro and a fully anonymous list, which is accepted by both
versions.

Fixes: f491059ed7 ("Enable building with SDL2")
This commit is contained in:
Kp 2018-07-29 16:13:15 +00:00
parent f491059ed7
commit c65020bf04

View file

@ -577,12 +577,13 @@ void key_flush()
return;
#if SDL_MAJOR_VERSION == 1
const auto &keystate = SDL_GetKeyState(nullptr);
constexpr auto sticky_keys = std::initializer_list<unsigned>{KEY_CAPSLOCK, KEY_NUMLOCK, KEY_SCROLLOCK};
#define DXX_SDL_STICKY_KEYS {KEY_CAPSLOCK, KEY_NUMLOCK, KEY_SCROLLOCK}
#elif SDL_MAJOR_VERSION == 2
const auto &keystate = SDL_GetKeyboardState(nullptr);
constexpr auto sticky_keys = std::initializer_list<unsigned>{SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_NUMLOCKCLEAR};
#define DXX_SDL_STICKY_KEYS {SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_NUMLOCKCLEAR}
#endif
range_for (const auto key, sticky_keys)
range_for (const auto key, DXX_SDL_STICKY_KEYS)
#undef DXX_SDL_STICKY_KEYS
restore_sticky_key(keystate, key);
}