You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Slint with C++ and CMake allows to specify the namespace in which the generated C++ code should live.
When using nested::namespaces and any of the nested parts (i.e. not the root namespace) equal slint verbatim, the generated code fails to compile as it clashes with the global slint namespace of the library.
Examples
Example namespaces, ❌ means it doesn't compile:
❌ Some nested namespace equals slint verbatim: some::nested::namespace::slint, ui::slint::stuff
✅ The whole namespace equals slint verbatim: slint
✅ The root namespace equals slint verbatim: slint::this::is::fine
✅ Any part of the namespace contains but not equalsslint: nested::slintstuff, nested::slintstuff::ui
I believe this is because the generated code tries to access the Slint library via the global slint namespace, but picks up the sorrounding user-defined namespace instead and thus the compiler fails to find the corresponding functions/members of the Slint library.
Proposed fix
This should be easily fixable by making the generated code always access the global slint namespace via ::slint syntax.
Additionally, I suggest disallowing slint as the complete namespace (slint::myui, myui::slint would be fine) as well. Otherwise, it would be possible to export, e.g., a SharedString global, which would always lead to compiler ambiguity with ::slint::SharedString.
Reproducible Code (if applicable)
cmake_minimum_required(VERSION 3.21)
project(example LANGUAGES CXX)
find_package(Slint REQUIRED)
add_executable(example main.cpp)
slint_target_sources(example ../ui/example.slint NAMESPACE this::is::problematic::slint)
target_link_libraries(example PUBLIC Slint::Slint)
Environment Details
Slint Version: 1.8.0
Platform/OS: N/A
Programming Language: C++, gcc
Backend/Renderer: N/A
Product Impact
Minor inconvience, should at least be documented
The text was updated successfully, but these errors were encountered:
Bug Description
Bug
Using Slint with C++ and CMake allows to specify the namespace in which the generated C++ code should live.
When using
nested::namespaces
and any of the nested parts (i.e. not the root namespace) equalslint
verbatim, the generated code fails to compile as it clashes with the globalslint
namespace of the library.Examples
Example namespaces, ❌ means it doesn't compile:
slint
verbatim:some::nested::namespace::slint
,ui::slint::stuff
slint
verbatim:slint
slint
verbatim:slint::this::is::fine
slint
:nested::slintstuff
,nested::slintstuff::ui
I believe this is because the generated code tries to access the Slint library via the global
slint
namespace, but picks up the sorrounding user-defined namespace instead and thus the compiler fails to find the corresponding functions/members of the Slint library.Proposed fix
This should be easily fixable by making the generated code always access the global
slint
namespace via::slint
syntax.Additionally, I suggest disallowing
slint
as the complete namespace (slint::myui
,myui::slint
would be fine) as well. Otherwise, it would be possible to export, e.g., aSharedString
global, which would always lead to compiler ambiguity with::slint::SharedString
.Reproducible Code (if applicable)
Environment Details
Product Impact
Minor inconvience, should at least be documented
The text was updated successfully, but these errors were encountered: