Try / Tempest

3d graphics engine
MIT License
83 stars 24 forks source link

Compilation warnings on GCC 10.2.1 #17

Closed Nindaleth closed 3 years ago

Nindaleth commented 3 years ago

I've noticed two warnings when compiling on Linux Fedora 32 using GCC 10.2.1:

/OpenGothic/lib/MoltenTempest/Engine/formats/image/pixmapcodeccommon.cpp: In function ‘void stbiSkip(void*, int)’:
/OpenGothic/lib/MoltenTempest/Engine/formats/image/pixmapcodeccommon.cpp:30:41: warning: ignoring return value of function declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |   reinterpret_cast<IDevice*>(user)->seek(size_t(n));
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~

/OpenGothic/lib/MoltenTempest/Engine/gapi/vulkan/vulkanapi_impl.cpp: In constructor ‘Tempest::Detail::VulkanApi::VulkanApi(bool)’:
/OpenGothic/lib/MoltenTempest/Engine/gapi/vulkan/vulkanapi_impl.cpp:36:51: warning: assignment from temporary ‘initializer_list’ does not extend the lifetime of the underlying array [-Winit-list-lifetime]
   36 |     validationLayers = checkValidationLayerSupport();
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
Try commented 3 years ago

Fixed the assignment from temporary warning.

For pixmapcodeccommon.cpp not sure how to go about it: stbiSkip is a stbi_io callback and it must return void, Looks like there is no way to propagate error, if IDevice::seek fails: stbi does't check 'seek-operation' exception is no an option - it will break a stbi internal cleanup

Nindaleth commented 3 years ago

Thanks for the fix!

For the other warning, if silencing it in this specific spot is acceptable, I've found two ways, one is standard C++17 (and so may not be usable by this project yet) [[maybe_unused]]:

static void stbiSkip(void* user, int n) {
  [[maybe_unused]] size_t s = reinterpret_cast<IDevice*>(user)->seek(size_t(n));
  }

the other one is a discarding workaround:

template<typename T>
void discard(const T&) {}

...

static void stbiSkip(void* user, int n) {
  discard(reinterpret_cast<IDevice*>(user)->seek(size_t(n)));
  }

I can confirm both silence the warning. I suppose if a complete solution is needed, stbi_image uptream would have to improve the stbi__skip implementation.