Skip to content

Cannot create vk::raii::ImageView with emplace_back on swapChainImageViews (clangd/MSVC/vulkan-raii error) #272

@XavierBeheydt

Description

@XavierBeheydt

Problem Description

When following the Vulkan tutorial's ImageViews section (Source page), I attempted to create the image views as shown:

swapChainImageViews.emplace_back(device, imageViewCreateInfo);

However, this triggers a build error with clangd:

In template: no matching function for call to 'construct_at'

My environment:

  • Microsoft Visual Studio Build Tools 2022
  • CMake 3.31.6-msvc6
  • Clang 9.1.5
  • clangd language server 19.1.5
  • Lunarg Vulkan SDK 1.4.335.0

The build errors I get:

C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\xmemory:730:9: error: no matching function for call to 'construct_at'
  730 |         _STD construct_at(_Ptr, _STD forward<_Types>(_Args)...);
      |         ^~~~~~~~~~~~~~~~~
...
C:/Users/xavie/Sources/GitHub/XavierBeheydt/Repos/project-aether/src/main. cpp:378:33: note:  in instantiation of function template specialization 'std::vector<vk::ImageView>::emplace_back<vk::raii::Device &, vk::ImageViewCreateInfo &>' requested here
  378 |             swapChainImageViews.emplace_back(device, imageViewCreateInfo);
      |                                 ^
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\xutility: 461:16: note: candidate template ignored: constraints not satisfied [with _Ty = vk::ImageView, _Types = <vk:: raii::Device &, vk::ImageViewCreateInfo &>]
  461 | constexpr _Ty* construct_at(_Ty* const _Location, _Types&&... _Args)
      |                ^
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\xutility:459:47: note: because '::new (static_cast<void *>(_Location)) _Ty(::std::forward<_Types>(_Args)...)' would be invalid: no matching constructor for initialization of 'vk::ImageView'

Workaround

As a workaround, I am currently using:

swapChainImageViews.push_back(vk::raii::ImageView(device, imageViewCreateInfo));

This change allows my project to build and run. Can you clarify why emplace_back fails here, and whether this is a documentation/tutorial issue or an environment/compatibility issue? Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions