Forbid implicit cast from Move<T> to bool
authorRicardo Garcia <rgarcia@igalia.com>
Wed, 1 Jun 2022 15:31:23 +0000 (17:31 +0200)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Thu, 9 Jun 2022 19:08:26 +0000 (19:08 +0000)
Take the following code:

  Move<VkPipelineLayout> smartLayout = ...;
  VkPipelineLayout rawLayout = smartLayout;

That builds and applies the following implicit conversions:

  Move<T> -> bool -> VkPipelineLayout

Which doesn't make any sense (the raw handle ends up having value "1")
and it's arguably an easy typo to make, when the second line should
actually have been one of:

  VkPipelineLayout rawLayout = *smartLayout;
  VkPipelineLayout rawLayout = smartLayout.get();

This commit disallows the implicit conversions from Move<T> to bool and
makes the typo fail compilatoin on purpose.

It also fixes one instance of such typo in the affected test, which was
causing issues when implementing graphics pipeline libraries in RADV.

Note the test also touches vktRenderPassTests.cpp, but the change should
not affect any test result there.

Affected tests:
dEQP-VK.pipeline.pipeline_library.graphics_library.misc.timing.compare_link_times

VK-GL-CTS issue: 3735
Components: Vulkan

Change-Id: Id968a1e74f6246e592257f7b3675c80e3363feaf

external/vulkancts/framework/vulkan/vkRef.hpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineLibraryTests.cpp
external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp

index 6967f14..958e1fe 100644 (file)
@@ -269,18 +269,18 @@ template<typename T>
 class RefBase
 {
 public:
-                                               ~RefBase        (void);
+                                               ~RefBase                (void);
 
-       inline const T&         get                     (void) const throw() { return m_data.object;    }
-       inline const T&         operator*       (void) const throw() { return get();                    }
-       inline operator         bool            (void) const throw() { return !!get();                  }
+       inline const T&         get                             (void) const throw() { return m_data.object;    }
+       inline const T&         operator*               (void) const throw() { return get();                    }
+       inline explicit         operator bool   (void) const throw() { return !!get();                  }
 
 protected:
-                                               RefBase         (RefData<T> data) : m_data(data)        {}
+                                               RefBase                 (RefData<T> data) : m_data(data)        {}
 
-       void                            reset           (void);                         //!< Release previous object, set to null.
-       RefData<T>                      disown          (void) throw();         //!< Disown and return object (ownership transferred to caller).
-       void                            assign          (RefData<T> data);      //!< Set new pointer, release previous pointer.
+       void                            reset                   (void);                         //!< Release previous object, set to null.
+       RefData<T>                      disown                  (void) throw();         //!< Disown and return object (ownership transferred to caller).
+       void                            assign                  (RefData<T> data);      //!< Set new pointer, release previous pointer.
 
 private:
        RefData<T>                      m_data;
index ff463ce..f67f6a1 100644 (file)
@@ -1799,7 +1799,7 @@ tcu::TestStatus PipelineLibraryMiscTestInstance::runCompareLinkTimes (void)
 
                VkPipelineLibraryCreateInfoKHR  linkingInfo                     = makePipelineLibraryCreateInfo(pipelinesToLink);
                VkGraphicsPipelineCreateInfo    finalPipelineInfo       = initVulkanStructure();
-               finalPipelineInfo.layout = layout;
+               finalPipelineInfo.layout = *layout;
 
                appendStructurePtrToVulkanChain(&finalPipelineInfo.pNext, &linkingInfo);
 
index 4ab1faa..f7c4d48 100644 (file)
@@ -2352,7 +2352,7 @@ public:
 
        bool isSecondary (void) const
        {
-               return m_commandBuffer;
+               return !!m_commandBuffer;
        }
 
        VkCommandBuffer getCommandBuffer (void) const