Change structure member sType to non-const to allow default assignment operator. Make copy constructor and copy assignment default. The latter is required for C++20 designated initializers. Delegate the constructor from C-type to the copy constructor by casting rhs accordingly. Fix warnings on gcc/clang.

This commit is contained in:
Markus Tavenrath 2021-01-07 16:04:52 +01:00
parent 822bcdcb4a
commit 160dc916f9
26 changed files with 4551 additions and 7034 deletions

View File

@ -113,7 +113,10 @@ add_executable(VulkanHppGenerator
set_property(TARGET VulkanHppGenerator PROPERTY CXX_STANDARD 14) set_property(TARGET VulkanHppGenerator PROPERTY CXX_STANDARD 14)
if(MSVC) if(MSVC)
target_compile_options(VulkanHppGenerator PRIVATE /W4 /WX /permissive-) target_compile_options(VulkanHppGenerator PRIVATE /W4 /WX)
if (MSVC_VER GREATER_EQUAL 1910)
target_compile_options(VulkanHppGenerator PRIVATE /permissive-)
endif()
else(MSVC) else(MSVC)
target_compile_options(VulkanHppGenerator PRIVATE -Wall -Wextra -pedantic -Werror) target_compile_options(VulkanHppGenerator PRIVATE -Wall -Wextra -pedantic -Werror)
endif(MSVC) endif(MSVC)

View File

@ -3054,20 +3054,18 @@ void VulkanHppGenerator::appendStructAssignmentOperators( std::string &
std::string const & prefix ) const std::string const & prefix ) const
{ {
static const std::string assignmentFromVulkanType = R"( static const std::string assignmentFromVulkanType = R"(
${prefix}${constexpr_assign}${structName} & operator=( ${structName} const & rhs ) VULKAN_HPP_NOEXCEPT = default;
${prefix}${structName} & operator=( Vk${structName} const & rhs ) VULKAN_HPP_NOEXCEPT ${prefix}${structName} & operator=( Vk${structName} const & rhs ) VULKAN_HPP_NOEXCEPT
${prefix}{ ${prefix}{
${prefix} *this = *reinterpret_cast<VULKAN_HPP_NAMESPACE::${structName} const *>( &rhs ); ${prefix} *this = *reinterpret_cast<VULKAN_HPP_NAMESPACE::${structName} const *>( &rhs );
${prefix} return *this; ${prefix} return *this;
${prefix}} ${prefix}}
${prefix}${structName} & operator=( ${structName} const & rhs ) VULKAN_HPP_NOEXCEPT
${prefix}{
${prefix} memcpy( static_cast<void *>( this ), &rhs, sizeof( ${structName} ) );
${prefix} return *this;
${prefix}}
)"; )";
str += replaceWithMap( assignmentFromVulkanType, str += replaceWithMap( assignmentFromVulkanType,
{ { "prefix", prefix }, { "structName", stripPrefix( structData.first, "Vk" ) } } ); { { "constexpr_assign", constructConstexprString( structData, true ) },
{ "prefix", prefix },
{ "structName", stripPrefix( structData.first, "Vk" ) } } );
} }
void VulkanHppGenerator::appendStructCompareOperators( std::string & str, void VulkanHppGenerator::appendStructCompareOperators( std::string & str,
@ -5353,13 +5351,13 @@ std::string VulkanHppGenerator::constructCommandVoidGetValue( std::string const
} }
std::string std::string
VulkanHppGenerator::constructConstexprString( std::pair<std::string, StructureData> const & structData ) const VulkanHppGenerator::constructConstexprString( std::pair<std::string, StructureData> const & structData, bool assignmentOperator ) const
{ {
// structs with a union (and VkBaseInStructure and VkBaseOutStructure) can't be a constexpr! // structs with a union (and VkBaseInStructure and VkBaseOutStructure) can't be a constexpr!
bool isConstExpression = !containsUnion( structData.first ) && ( structData.first != "VkBaseInStructure" ) && bool isConstExpression = !containsUnion( structData.first ) && ( structData.first != "VkBaseInStructure" ) &&
( structData.first != "VkBaseOutStructure" ); ( structData.first != "VkBaseOutStructure" );
return isConstExpression return isConstExpression
? ( std::string( "VULKAN_HPP_CONSTEXPR" ) + ( containsArray( structData.first ) ? "_14 " : " " ) ) ? ( std::string( "VULKAN_HPP_CONSTEXPR" ) + ( (containsArray( structData.first ) || assignmentOperator) ? "_14 " : " " ) )
: ""; : "";
} }
@ -5611,9 +5609,8 @@ ${prefix}{}
${prefix}${constexpr}${structName}( ${structName} const & rhs ) VULKAN_HPP_NOEXCEPT = default; ${prefix}${constexpr}${structName}( ${structName} const & rhs ) VULKAN_HPP_NOEXCEPT = default;
${prefix}${structName}( Vk${structName} const & rhs ) VULKAN_HPP_NOEXCEPT ${prefix}${structName}( Vk${structName} const & rhs ) VULKAN_HPP_NOEXCEPT
${prefix}{ ${prefix} : ${structName}( *reinterpret_cast<${structName} const *>( &rhs ) )
${prefix} *this = rhs; ${prefix}{}
${prefix}}
)"; )";
std::string arguments, initializers; std::string arguments, initializers;
@ -5634,7 +5631,7 @@ ${prefix}}
str += replaceWithMap( constructors, str += replaceWithMap( constructors,
{ { "arguments", arguments }, { { "arguments", arguments },
{ "constexpr", constructConstexprString( structData ) }, { "constexpr", constructConstexprString( structData, false ) },
{ "initializers", initializers }, { "initializers", initializers },
{ "prefix", prefix }, { "prefix", prefix },
{ "structName", stripPrefix( structData.first, "Vk" ) } } ); { "structName", stripPrefix( structData.first, "Vk" ) } } );
@ -5787,11 +5784,6 @@ std::string VulkanHppGenerator::appendStructMembers( std::string &
for ( auto const & member : structData.second.members ) for ( auto const & member : structData.second.members )
{ {
str += prefix; str += prefix;
if ( member.values.size() == 1 )
{
// members with just one allowed value are set to be const
str += "const ";
}
if ( !member.bitCount.empty() && beginsWith( member.type.type, "Vk" ) ) if ( !member.bitCount.empty() && beginsWith( member.type.type, "Vk" ) )
{ {
assert( member.type.prefix.empty() && member.type.postfix.empty() ); // never encounterd a different case assert( member.type.prefix.empty() && member.type.postfix.empty() ); // never encounterd a different case
@ -9716,6 +9708,11 @@ int main( int argc, char ** argv )
, m_ptr( ptr ) , m_ptr( ptr )
{} {}
#if __GNUC__ >= 9
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winit-list-lifetime"
#endif
ArrayProxy( std::initializer_list<T> const & list ) VULKAN_HPP_NOEXCEPT ArrayProxy( std::initializer_list<T> const & list ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( list.size() ) ) : m_count( static_cast<uint32_t>( list.size() ) )
, m_ptr( list.begin() ) , m_ptr( list.begin() )
@ -9738,6 +9735,10 @@ int main( int argc, char ** argv )
, m_ptr( list.begin() ) , m_ptr( list.begin() )
{} {}
#if __GNUC__ >= 9
#pragma GCC diagnostic pop
#endif
template <size_t N> template <size_t N>
ArrayProxy( std::array<T, N> const & data ) VULKAN_HPP_NOEXCEPT ArrayProxy( std::array<T, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( N ) : m_count( N )

View File

@ -599,7 +599,7 @@ private:
bool definition, bool definition,
std::map<size_t, size_t> const & vectorParamIndices, std::map<size_t, size_t> const & vectorParamIndices,
size_t returnParamIndex ) const; size_t returnParamIndex ) const;
std::string constructConstexprString( std::pair<std::string, StructureData> const & structData ) const; std::string constructConstexprString( std::pair<std::string, StructureData> const & structData, bool assignmentOperator ) const;
std::string constructFunctionBodyEnhanced( std::string const & indentation, std::string constructFunctionBodyEnhanced( std::string const & indentation,
std::string const & name, std::string const & name,
CommandData const & commandData, CommandData const & commandData,

View File

@ -15,16 +15,6 @@
// VulkanHpp Samples : 13_InitVertexBuffer // VulkanHpp Samples : 13_InitVertexBuffer
// Initialize vertex buffer // Initialize vertex buffer
#if defined( _MSC_VER )
// no need to ignore any warnings with MSVC
#elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else
// unknow compiler... just ignore the warnings for yourselves ;)
#endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/utils.hpp" #include "../utils/utils.hpp"
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"

View File

@ -15,16 +15,6 @@
// VulkanHpp Samples : 15_DrawCube // VulkanHpp Samples : 15_DrawCube
// Draw a cube // Draw a cube
#if defined( _MSC_VER )
// no need to ignore any warnings with MSVC
#elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else
// unknow compiler... just ignore the warnings for yourselves ;)
#endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"

View File

@ -15,16 +15,6 @@
// VulkanHpp Samples : DrawTexturedCube // VulkanHpp Samples : DrawTexturedCube
// Draw a textured cube // Draw a textured cube
#if defined( _MSC_VER )
// no need to ignore any warnings with MSVC
#elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else
// unknow compiler... just ignore the warnings for yourselves ;)
#endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"

View File

@ -15,21 +15,22 @@
// VulkanHpp Samples : DynamicUniform // VulkanHpp Samples : DynamicUniform
// Draw 2 Cubes using dynamic uniform buffer // Draw 2 Cubes using dynamic uniform buffer
#if defined( _MSC_VER )
# pragma warning( disable : 4127 ) // conditional expression is constant
#elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else
// unknow compiler... just ignore the warnings for yourselves ;)
#endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"
#include "../utils/utils.hpp" #include "../utils/utils.hpp"
#if defined( _MSC_VER )
# pragma warning( push )
# pragma warning( disable : 4100 ) // unreferenced formal parameter (glslang)
#endif // endif (_MSC_VER )
#include "SPIRV/GlslangToSpv.h" #include "SPIRV/GlslangToSpv.h"
#if defined( _MSC_VER )
# pragma warning( pop )
#endif
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include <iostream> #include <iostream>

View File

@ -20,9 +20,6 @@
#elif defined( __clang__ ) #elif defined( __clang__ )
# pragma clang diagnostic ignored "-Wmissing-braces" # pragma clang diagnostic ignored "-Wmissing-braces"
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else #else
// unknow compiler... just ignore the warnings for yourselves ;) // unknow compiler... just ignore the warnings for yourselves ;)
#endif #endif

View File

@ -21,9 +21,6 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
static char const * AppName = "InstanceExtensionProperties";
static char const * EngineName = "Vulkan.hpp";
int main( int /*argc*/, char ** /*argv*/ ) int main( int /*argc*/, char ** /*argv*/ )
{ {
try try

View File

@ -21,9 +21,6 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
static char const * AppName = "InstanceLayerExtensionProperties";
static char const * EngineName = "Vulkan.hpp";
struct PropertyData struct PropertyData
{ {
PropertyData( vk::LayerProperties const & layerProperties_, PropertyData( vk::LayerProperties const & layerProperties_,

View File

@ -21,9 +21,6 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
static char const * AppName = "InstanceLayerProperties";
static char const * EngineName = "Vulkan.hpp";
int main( int /*argc*/, char ** /*argv*/ ) int main( int /*argc*/, char ** /*argv*/ )
{ {
try try

View File

@ -20,9 +20,6 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
static char const * AppName = "InstanceVersion";
static char const * EngineName = "Vulkan.hpp";
std::string decodeAPIVersion( uint32_t apiVersion ) std::string decodeAPIVersion( uint32_t apiVersion )
{ {
return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) + return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) +

View File

@ -20,9 +20,6 @@
#elif defined( __clang__ ) #elif defined( __clang__ )
# pragma clang diagnostic ignored "-Wmissing-braces" # pragma clang diagnostic ignored "-Wmissing-braces"
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else #else
// unknow compiler... just ignore the warnings for yourselves ;) // unknow compiler... just ignore the warnings for yourselves ;)
#endif #endif

View File

@ -15,16 +15,6 @@
// VulkanHpp Samples : OcclusionQuery // VulkanHpp Samples : OcclusionQuery
// Use occlusion query to determine if drawing renders any samples. // Use occlusion query to determine if drawing renders any samples.
#if defined( _MSC_VER )
// no need to ignore any warnings with MSVC
#elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else
// unknow compiler... just ignore the warnings for yourselves ;)
#endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"

View File

@ -20,13 +20,9 @@
#elif defined( __clang__ ) #elif defined( __clang__ )
# pragma clang diagnostic ignored "-Wmissing-braces" # pragma clang diagnostic ignored "-Wmissing-braces"
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else #else
// unknow compiler... just ignore the warnings for yourselves ;) // unknow compiler... just ignore the warnings for yourselves ;)
#endif #endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"

View File

@ -20,13 +20,9 @@
#elif defined( __clang__ ) #elif defined( __clang__ )
# pragma clang diagnostic ignored "-Wmissing-braces" # pragma clang diagnostic ignored "-Wmissing-braces"
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else #else
// unknow compiler... just ignore the warnings for yourselves ;) // unknow compiler... just ignore the warnings for yourselves ;)
#endif #endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"

View File

@ -20,13 +20,9 @@
#elif defined( __clang__ ) #elif defined( __clang__ )
# pragma clang diagnostic ignored "-Wmissing-braces" # pragma clang diagnostic ignored "-Wmissing-braces"
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else #else
// unknow compiler... just ignore the warnings for yourselves ;) // unknow compiler... just ignore the warnings for yourselves ;)
#endif #endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"

View File

@ -15,16 +15,6 @@
// VulkanHpp Samples : PushDescriptors // VulkanHpp Samples : PushDescriptors
// Use Push Descriptors to Draw Textured Cube // Use Push Descriptors to Draw Textured Cube
#if defined( _MSC_VER )
// no need to ignore any warnings with MSVC
#elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else
// unknow compiler... just ignore the warnings for yourselves ;)
#endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"

View File

@ -15,7 +15,17 @@
#pragma once #pragma once
#if defined( _MSC_VER )
# pragma warning( push )
# pragma warning( disable : 4127 ) // conditional expression is constant (glm)
#endif
#include <glm/glm.hpp> #include <glm/glm.hpp>
#if defined( _MSC_VER )
# pragma warning( pop )
#endif
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
namespace vk namespace vk

View File

@ -24,9 +24,6 @@
# pragma clang diagnostic ignored "-Wdeprecated-volatile" // to keep glm/detail/type_half.inl compiling # pragma clang diagnostic ignored "-Wdeprecated-volatile" // to keep glm/detail/type_half.inl compiling
# endif # endif
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else #else
// unknow compiler... just ignore the warnings for yourselves ;) // unknow compiler... just ignore the warnings for yourselves ;)
#endif #endif

View File

@ -20,9 +20,6 @@
#elif defined( __clang__ ) #elif defined( __clang__ )
# pragma clang diagnostic ignored "-Wmissing-braces" # pragma clang diagnostic ignored "-Wmissing-braces"
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else #else
// unknow compiler... just ignore the warnings for yourselves ;) // unknow compiler... just ignore the warnings for yourselves ;)
#endif #endif

View File

@ -15,16 +15,6 @@
// VulkanHpp Samples : Template // VulkanHpp Samples : Template
// Template sample to start from. Draw textured cube with mostly helpers. // Template sample to start from. Draw textured cube with mostly helpers.
#if defined( _MSC_VER )
// no need to ignore any warnings with MSVC
#elif defined( __GNUC__ )
# if ( 9 <= __GNUC__ )
# pragma GCC diagnostic ignored "-Winit-list-lifetime"
# endif
#else
// unknow compiler... just ignore the warnings for yourselves ;)
#endif
#include "../utils/geometries.hpp" #include "../utils/geometries.hpp"
#include "../utils/math.hpp" #include "../utils/math.hpp"
#include "../utils/shaders.hpp" #include "../utils/shaders.hpp"

View File

@ -25,8 +25,18 @@
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
#if defined( _MSC_VER )
# pragma warning( push )
# pragma warning( disable : 4127 ) // conditional expression is constant (glm)
#endif
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#if defined( _MSC_VER )
# pragma warning( pop )
#endif
namespace vk namespace vk
{ {
namespace su namespace su

View File

@ -18,9 +18,6 @@
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include <iostream> #include <iostream>
static char const* AppName = "ArrayProxy";
static char const* EngineName = "Vulkan.hpp";
void fct(vk::ArrayProxy<int> /*ap*/) void fct(vk::ArrayProxy<int> /*ap*/)
{} {}

View File

@ -21,6 +21,10 @@
#include <iostream> #include <iostream>
#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
int main( int /*argc*/, char ** /*argv*/ ) int main( int /*argc*/, char ** /*argv*/ )
{ {
char const * appName = "DesignatedInitializers"; char const * appName = "DesignatedInitializers";

File diff suppressed because it is too large Load Diff