Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
error: can't convert from brace-enclosed initializer list
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
KWhat
l33t
l33t


Joined: 04 Sep 2005
Posts: 658
Location: Los Angeles

PostPosted: Tue Jul 02, 2024 6:36 am    Post subject: error: can't convert from brace-enclosed initializer list Reply with quote

I need some help with some CPP errors I am getting trying to fix an ebuild. Basically it doesn't like
Code:
.source_type = InputSourceType::SDL
as an InputSourceType in the structure and I have no idea why. The relevant code is below:

Code:

enum class InputSourceType : u32
{
  Keyboard,
  Pointer,
  Sensor,
#ifdef _WIN32
  DInput,
  XInput,
  RawInput,
#endif
#ifndef __ANDROID__
  SDL,
#else
  Android,
#endif
  Count,
};


union InputBindingKey
{
  struct
  {
    InputSourceType source_type : 4;
    u32 source_index : 8;             ///< controller number
    InputSubclass source_subtype : 3; ///< if 1, binding is for an axis and not a button (used for controllers)
    InputModifier modifier : 2;
    u32 invert : 1; ///< if 1, value is inverted prior to being sent to the sink
    u32 unused : 14;
    u32 data;
  };

  u64 bits;

  bool operator==(const InputBindingKey& k) const { return bits == k.bits; }
  bool operator!=(const InputBindingKey& k) const { return bits != k.bits; }

  /// Removes the direction bit from the key, which is used to look up the bindings for it.
  /// This is because negative bindings should still fire when they reach zero again.
  InputBindingKey MaskDirection() const
  {
    InputBindingKey r;
    r.bits = bits;
    r.modifier = InputModifier::None;
    r.invert = 0;
    return r;
  }
};

void OnInputDeviceDisconnected(InputBindingKey key, std::string_view identifier);

InputManager::OnInputDeviceDisconnected(
  {{.source_type = InputSourceType::SDL, .source_index = static_cast<u32>(it->player_id)}},
  fmt::format("SDL-{}", it->player_id));

 
 error: could not convert ‘{{<expression error>, ((u32)it.__gnu_cxx::__normal_iterator<SDLInputSource::ControllerData*, std::vector<SDLInputSource::ControllerData> >::operator->()->SDLInputSource::ControllerData::player_id), 0}}’ from ‘<brace-enclosed initializer list>’ to ‘InputBindingKey’
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1705
Location: South America

PostPosted: Tue Jul 02, 2024 3:21 pm    Post subject: Re: can't convert from brace-enclosed initializer list Reply with quote

KWhat wrote:
Code:
void OnInputDeviceDisconnected(InputBindingKey key, std::string_view identifier);

InputManager::OnInputDeviceDisconnected(
  {{.source_type = InputSourceType::SDL, .source_index = static_cast<u32>(it->player_id)}},
  fmt::format("SDL-{}", it->player_id));

I don't know the context here, but designated initializers (i. e. class member names after a period in initializer lists) like those are C only, unless you compile in C++ 2020 mode.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22686

PostPosted: Tue Jul 02, 2024 3:27 pm    Post subject: Reply with quote

Please provide a Minimal Reproducible Example. The shown question lacks:
  • The compiler command line used, which would address the point GDH-gentoo raised. We need to know if the compiler is even invoked in a way that your construct could work.
  • Requisite typedefs. u32 is not a built-in type in C++. We can guess that it is an unsigned 32-bit value, but it would be easier for us if you posted something that does not require us to edit it before we can see the error you want to discuss.
  • Appropriate function framing. A naive reading of your post would put the function call at global scope, which doesn't make sense here, and cannot work anyway since there is no class or namespace named InputManager.
Since this is for an ebuild, an alternative approach would've been to point us to the ebuild, so that we can run it and see for ourselves what it does to the upstream source.
Back to top
View user's profile Send private message
KWhat
l33t
l33t


Joined: 04 Sep 2005
Posts: 658
Location: Los Angeles

PostPosted: Tue Jul 02, 2024 5:21 pm    Post subject: Reply with quote

Apologies for the abstract code, but its part of duckstation which is horribly broken in guru and I am working on trying to get it to build. There isn't much I can provide a minimal example outside of the entire code base: https://github.com/stenzek/duckstation/tree/latest

I can add the compiler call:

Code:

FAILED: src/util/CMakeFiles/util.dir/sdl_input_source.cpp.o
/usr/bin/x86_64-pc-linux-gnu-g++ -DENABLE_EGL=1 -DENABLE_OPENGL=1 -DENABLE_VULKAN=1 -DENABLE_WAYLAND=1 -DENABLE_X11=1 -DSOUNDTOUCH_FLOAT_SAMPLES -DST_NO_EXCEPTION_HANDLING=1 -DXXH_STATIC_LINKING_ONLY -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/.. -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/elogind -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/common/.. -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/fmt/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/fast_float/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/simpleini/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/imgui/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/libchdr/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/soundtouch/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/xxhash/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/reshadefx/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/glad/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/vulkan/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/cubeb/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/freesurround/include -I/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/dep/kissfft/include -isystem /usr/include/freetype2 -isystem /usr/include/SDL2  -march=native -mtune=native -O2 -fomit-frame-pointer -pipe -Wall -Wno-class-memaccess -Wno-invalid-offsetof -Wno-switch -fno-exceptions -fno-rtti -DFMT_EXCEPTIONS=0 -std=gnu++20 -MD -MT src/util/CMakeFiles/util.dir/sdl_input_source.cpp.o -MF src/util/CMakeFiles/util.dir/sdl_input_source.cpp.o.d -o src/util/CMakeFiles/util.dir/sdl_input_source.cpp.o -c /var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/sdl_input_source.cpp
/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/sdl_input_source.cpp: In member function ‘bool SDLInputSource::CloseDevice(int)’:
/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/sdl_input_source.cpp:825:22: error: ‘SDL’ was not declared in this scope
  825 |     {{.source_type = SDL, .source_index = static_cast<u32>(it->player_id), .data = static_cast<u32>(0)}},
      |                      ^~~
/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/sdl_input_source.cpp:825:22: note: suggested alternatives:
In file included from /var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/../core/settings.h:8,
                 from /var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/sdl_input_source.cpp:8:
/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/../util/audio_stream.h:33:3: note:   ‘AudioBackend::SDL’
   33 |   SDL,
      |   ^~~
In file included from /var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/input_source.h:15,
                 from /var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/sdl_input_source.h:5,
                 from /var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/sdl_input_source.cpp:4:
/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/input_manager.h:33:3: note:   ‘InputSourceType::SDL’
   33 |   SDL,
      |   ^~~
/var/tmp/portage/games-emulation/duckstation-9999/work/duckstation/src/util/sdl_input_source.cpp:824:42: error: could not convert ‘{{<expression error>, ((u32)it.__gnu_cxx::__normal_iterator<SDLInputSource::ControllerData*, std::vector<SDLInputSource::ControllerData> >::operator->()->SDLInputSource::ControllerData::player_id), 0}}’ from ‘<brace-enclosed initializer list>’ to ‘InputBindingKey’
  824 |   InputManager::OnInputDeviceDisconnected(
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      |                                          |
      |                                          <brace-enclosed initializer list>
  825 |     {{.source_type = SDL, .source_index = static_cast<u32>(it->player_id), .data = static_cast<u32>(0)}},
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  826 |     fmt::format("SDL-{}", it->player_id));
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Back to top
View user's profile Send private message
KWhat
l33t
l33t


Joined: 04 Sep 2005
Posts: 658
Location: Los Angeles

PostPosted: Tue Jul 02, 2024 5:31 pm    Post subject: Reply with quote

games-emulation/duckstation/duckstation-9999.ebuild
Code:

# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

inherit xdg cmake desktop git-r3

DESCRIPTION="Fast Sony PlayStation (PSX) emulator"
HOMEPAGE="https://github.com/stenzek/duckstation"
EGIT_REPO_URI="https://github.com/stenzek/duckstation.git"
EGIT_CHECKOUT_DIR="${WORKDIR}/${PN}"
EGIT_SUBMODULES=()

LICENSE="GPL-3"
SLOT="0"
IUSE="cubeb discord +egl +gamepad nogui opengl +qt6 vulkan wayland X"

# Either or both frontends must be built
REQUIRED_USE="
        || ( nogui wayland X )
        opengl? ( egl )
        qt6? (
                || ( wayland X )
        )
        !qt6? ( nogui )
        wayland? ( qt6 )
"

BDEPEND="
        dev-util/spirv-cross
        sys-libs/libbacktrace
        virtual/pkgconfig
        wayland? ( kde-frameworks/extra-cmake-modules )
"
DEPEND="
        cubeb? ( media-libs/cubeb )
        net-misc/curl[ssl]
        sys-apps/dbus
        gamepad? ( >=media-libs/libsdl2-2.28.2 )
        opengl? ( virtual/opengl )
        qt6? (
                dev-qt/qtbase:6[gui,network,widgets]
                dev-qt/qttools:6[linguist]
        )
        vulkan? ( media-libs/vulkan-loader )
        wayland? ( dev-qt/qtwayland:6 )
        X? (
                x11-libs/libX11
                x11-libs/libXrandr
        )
"
RDEPEND="${DEPEND}"

S="${WORKDIR}/${PN}"

src_prepare() {
        eapply "${FILESDIR}/missing-utility-header.patch"
        eapply "${FILESDIR}/sdl2-input-disconnect.patch"
        eapply "${FILESDIR}/sdl2-version.patch"
        eapply "${FILESDIR}/vanilla-shaderc.patch"

        eapply_user
        cmake_src_prepare
}

src_configure() {
        local mycmakeargs=(
                -DENABLE_CUBEB=ON
                -DBUILD_NOGUI_FRONTEND=$(usex nogui)
                -DBUILD_QT_FRONTEND=$(usex qt6)
                -DENABLE_CUBEB=$(usex cubeb)
                -DENABLE_DISCORD_PRESENCE=$(usex discord)
                -DENABLE_EGL=$(usex egl)
                -DENABLE_SDL2=$(usex gamepad)
                -DENABLE_OPENGL=$(usex opengl)
                -DENABLE_VULKAN=$(usex vulkan)
                -DENABLE_WAYLAND=$(usex wayland)
                -DENABLE_X11=$(usex X)
                -DBUILD_SHARED_LIBS=OFF
        )
        cmake_src_configure
}

src_install() {
        dodoc README.md

        # Binary and resources files must be in same directory – installing in /opt
        insinto /opt/${PN}
        doins -r "${S}"/data/resources/

        if use nogui; then
                newicon "${S}"/data/resources/images/duck.png duckstation-nogui.png
                make_desktop_entry "${PN}-nogui %f" "DuckStation NoGUI" "${PN}-nogui" "Game"

                doins "${BUILD_DIR}"/bin/duckstation-nogui
                dosym ../../opt/${PN}/duckstation-nogui usr/bin/duckstation-nogui
                fperms +x /opt/${PN}/duckstation-nogui
        fi

        if use qt6; then
                newicon "${BUILD_DIR}"/bin/resources/images/duck.png duckstation-qt.png
                make_desktop_entry "${PN}-qt %f" "DuckStation Qt" "${PN}-qt" "Game"

                doins -r "${BUILD_DIR}"/bin/translations/
                doins "${BUILD_DIR}"/bin/duckstation-qt
                dosym ../../opt/${PN}/duckstation-qt usr/bin/duckstation-qt
                fperms +x /opt/${PN}/duckstation-qt
        fi
}


files/missing-utility-header.patch
Code:

--- ./src/core/gpu_commands.cpp 2024-04-11 17:18:51.869803192 -0700
+++ ./src/core/gpu_commands.cpp 2024-04-11 17:19:29.532988636 -0700
@@ -1,6 +1,7 @@
 // SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
 
+#include <utility>
 #include "common/assert.h"
 #include "common/log.h"
 #include "common/string_util.h"


games-emulation/duckstation/files/sdl2-input-disconnect.patch
Code:

--- ./src/util/sdl_input_source.cpp     2024-07-01 22:27:17.776007354 -0700
+++ ./src/util/sdl_input_source.cpp     2024-07-01 22:40:22.013559313 -0700
@@ -821,9 +821,9 @@
   if (it == m_controllers.end())
     return false;
 
-  InputManager::OnInputDeviceDisconnected(
-    {{.source_type = InputSourceType::SDL, .source_index = static_cast<u32>(it->player_id)}},
-    fmt::format("SDL-{}", it->player_id));
+  InputManager::OnInputDeviceDisconnected(
+    {{.source_type = InputSourceType::SDL, .source_index = static_cast<u32>(it->player_id), .data = static_cast<u32>(0)}},
+    fmt::format("SDL-{}", it->player_id));
 
   if (it->haptic)
     SDL_HapticClose(it->haptic)


games-emulation/duckstation/files/sdl2-version.patch
Code:

--- ./CMakeModules/DuckStationDependencies.cmake.orig   2024-06-25 20:16:41.731823844 -0700
+++ ./CMakeModules/DuckStationDependencies.cmake        2024-06-25 20:16:00.091532727 -0700
@@ -9,7 +9,7 @@
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads REQUIRED)
 
-find_package(SDL2 2.30.4 REQUIRED)
+find_package(SDL2 2.30.3 REQUIRED)
 find_package(Zstd 1.5.6 REQUIRED)
 find_package(WebP REQUIRED) # v1.4.0, spews an error on Linux because no pkg-config.
 find_package(ZLIB REQUIRED) # 1.3, but Mac currently doesn't use it.


games-emulation/duckstation/files/vanilla-shaderc.patch
Code:

--- ./src/util/gpu_device.cpp    2024-07-01 22:08:26.195708463 -0700
+++ ./src/util/gpu_device.cpp    2024-07-01 22:11:36.615636126 -0700
@@ -1127,7 +1127,7 @@
   X(shaderc_compile_options_set_generate_debug_info)                                                                   \
   X(shaderc_compile_options_set_optimization_level)                                                                    \
   X(shaderc_compile_options_set_target_env)                                                                            \
-  X(shaderc_compilation_status_to_string)                                                                              \
+  X(shaderc_result_get_compilation_status)                                                                             \
   X(shaderc_compile_into_spv)                                                                                          \
   X(shaderc_result_release)                                                                                            \
   X(shaderc_result_get_length)                                                                                         \
@@ -1324,22 +1324,19 @@
 
   dyn_libs::shaderc_compile_options_set_source_language(options, shaderc_source_language_glsl);
   dyn_libs::shaderc_compile_options_set_target_env(options, shaderc_target_env_vulkan, 0);
-  dyn_libs::shaderc_compile_options_set_generate_debug_info(options, m_debug_device,
-                                                            m_debug_device && nonsemantic_debug_info);
+  dyn_libs::shaderc_compile_options_set_generate_debug_info(options);
   dyn_libs::shaderc_compile_options_set_optimization_level(
     options, optimization ? shaderc_optimization_level_performance : shaderc_optimization_level_zero);
 
-  shaderc_compilation_result_t result;
-  const shaderc_compilation_status status = dyn_libs::shaderc_compile_into_spv(
+  shaderc_compilation_result_t result = dyn_libs::shaderc_compile_into_spv(
     dyn_libs::s_shaderc_compiler, source.data(), source.length(), stage_kinds[static_cast<size_t>(stage)], "source",
-    entry_point, options, &result);
+    entry_point, options);
+  shaderc_compilation_status status = dyn_libs::shaderc_result_get_compilation_status(result);
   if (status != shaderc_compilation_status_success)
   {
     const std::string_view errors(result ? dyn_libs::shaderc_result_get_error_message(result) : "null result object");
-    Error::SetStringFmt(error, "Failed to compile shader to SPIR-V: {}\n{}",
-                        dyn_libs::shaderc_compilation_status_to_string(status), errors);
-    ERROR_LOG("Failed to compile shader to SPIR-V: {}\n{}", dyn_libs::shaderc_compilation_status_to_string(status),
-              errors);
+    Error::SetStringFmt(error, "Failed to compile shader to SPIR-V: {}", errors);
+    ERROR_LOG("Failed to compile shader to SPIR-V: {}", errors);
     DumpBadShader(source, errors);
   }
   else


dev-util/spirv-cross/spirv-cross-20240619.ebuild
Code:

# Copyright 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit cmake

DESCRIPTION="Tool for performing reflection on SPIR-V."
HOMEPAGE="https://github.com/KhronosGroup/SPIRV-Cross"
SHA="6fd1f75636b1c424b809ad8a84804654cf5ae48b"
SRC_URI="https://github.com/KhronosGroup/SPIRV-Cross/archive/${SHA}.tar.gz -> ${PN}-${SHA:0:7}.tar.gz"

LICENSE="Apache-2"
SLOT="0"
KEYWORDS="~amd64"

S="${WORKDIR}/SPIRV-Cross-${SHA}"

src_configure() {
        local mycmakeargs=(
                -DSPIRV_CROSS_SHARED=ON
        )
        cmake_src_configure
}


sys-libs/libbacktrace/libbacktrace-1.0_p20230329.ebuild
Code:

# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit autotools

DESCRIPTION="C library that may be linked into a C/C++ program to produce symbolic backtraces"
HOMEPAGE="https://github.com/ianlancetaylor/libbacktrace"
COMMITHASH="cdb64b688dda93bbbacbc2b1ccf50ce9329d4748"
SRC_URI="${HOMEPAGE}/archive/${COMMITHASH}.tar.gz -> ${P}.tar.gz
        ${HOMEPAGE}/commit/6674aadb6f2be925e89b253f1b380ecdbc69777b.patch?full_index=1 -> ${PN}-libtool-no-wrap-tests.patch"
S="${WORKDIR}/${PN}-${COMMITHASH}"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~arm ~arm64 ~mips ~ppc64 ~riscv ~x86"
IUSE="static-libs test"
RESTRICT="!test? ( test )"

PATCHES=(
        "${DISTDIR}/${PN}-libtool-no-wrap-tests.patch"
)

BDEPEND="
        test? (
                app-arch/xz-utils
                sys-libs/zlib
        )
"

src_prepare() {
        default
        eautoreconf
}

src_configure() {
        econf --enable-shared \
                $(use_enable static{-libs,})
}

src_install() {
        default
        find "${D}" -name '*.la' -delete || die
}
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22686

PostPosted: Tue Jul 02, 2024 6:14 pm    Post subject: Reply with quote

Your error output shows that the enum reference is not fully qualified, which is definitely wrong when dealing with an enum class member. Your original post shows it is properly qualified. Does the ebuild still fail if you make that line look like it did in the opening post?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum