This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit 335a75c148a7831c3ae4e5b31b81c5b9300978a3
Author: Cedric BAIL <[email protected]>
AuthorDate: Thu Nov 12 21:22:09 2026 -0600
eolian_cxx: a const object converts to its base wrapper
Each generated eo_cxx view struct declared three conversions to the
concrete wrapper: operator Class() const, operator Class&() and
operator Class const&() const. Converting a const lvalue of a derived
wrapper to a by-value base parameter (a Generic_Model const to the
Efl.Model that in_traits gives for Efl.Ui.View.model_set) found both
operator Model() const and operator Model const&() const plus the copy
constructor as viable user-defined conversions, which is ambiguous.
Non-const objects picked operator Model&() and compiled.
The by-value operator is redundant: operator Class const&() const and
the copy constructor yield the same value. Stop generating it, keep the
two reference conversions.
What only the by-value operator allowed is lost with it: binding a
Base&& to a derived lvalue (accepted by clang, already rejected by gcc)
and calling x.operator Class() by name. No generated API takes a
wrapper by rvalue reference, and a Base&& to a copy of a live object
was a temporary anyway; a by-value or const& parameter is what to use.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../eolian_cxx/grammar/base_class_definition.hpp | 6 ++--
.../eolian_cxx/grammar/class_implementation.hpp | 4 +--
src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc | 38 ++++++++++++++++++++++
3 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/src/lib/eolian_cxx/grammar/base_class_definition.hpp b/src/lib/eolian_cxx/grammar/base_class_definition.hpp
index 59a87ff069..17a8d6dfa5 100644
--- a/src/lib/eolian_cxx/grammar/base_class_definition.hpp
+++ b/src/lib/eolian_cxx/grammar/base_class_definition.hpp
@@ -89,16 +89,14 @@ struct base_class_definition_generator
).generate(sink, cls.cxx_name, context))
return false;
- // operator ::ns::Class_Name() const;
// operator ::ns::Class_Name&();
// operator ::ns::Class_Name const&() const;
auto class_name = *(lit("::") << lower_case[string]) << "::" << string;
if(!as_generator
(
- attribute_reorder<0, 1, 0, 1, 0, 1, 0, 1>
+ attribute_reorder<0, 1, 0, 1>
(
- scope_tab << "operator " << class_name << "() const;\n"
- << scope_tab << "operator " << class_name << "&();\n"
+ scope_tab << "operator " << class_name << "&();\n"
<< scope_tab << "operator " << class_name << " const&() const;\n"
)).generate(sink, std::make_tuple(cpp_namespaces, cls.cxx_name), context))
return false;
diff --git a/src/lib/eolian_cxx/grammar/class_implementation.hpp b/src/lib/eolian_cxx/grammar/class_implementation.hpp
index 744a2f0fb7..70f2d9ea27 100644
--- a/src/lib/eolian_cxx/grammar/class_implementation.hpp
+++ b/src/lib/eolian_cxx/grammar/class_implementation.hpp
@@ -72,15 +72,13 @@ struct class_implementation_generator
#endif
if(!as_generator(
- attribute_reorder<0, 1, 4, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3>
+ attribute_reorder<0, 1, 4, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3>
(
"namespace eo_cxx {\n"
<< namespaces
[
*function_definition(get_klass_name(cls))
<< *part_implementation(cls.cxx_name)
- << "inline " << base_class_name << "::operator " << class_name << "() const { return *static_cast< "
- << class_name << " const*>(static_cast<void const*>(this)); }\n"
<< "inline " << base_class_name << "::operator " << class_name << "&() { return *static_cast< "
<< class_name << "*>(static_cast<void*>(this)); }\n"
<< "inline " << base_class_name << "::operator " << class_name << " const&() const { return *static_cast< "
diff --git a/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc b/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
index e1d585cfab..8c4c15ae3c 100644
--- a/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
+++ b/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
@@ -24,6 +24,11 @@
#define EOLIANCXXTEST_API_WEAK
#include <a.eo.hh>
+#include <a.eo.impl.hh>
+#include <b.eo.hh>
+#include <b.eo.impl.hh>
+#include <c.eo.hh>
+#include <c.eo.impl.hh>
#include "eolian_cxx_suite.h"
@@ -39,8 +44,41 @@ EFL_START_TEST(eolian_cxx_test_wrapper_size)
}
EFL_END_TEST
+/* A const object of a derived wrapper converts to a by-value base wrapper. */
+static Eo*
+take_base(nonamespace::A a)
+{
+ return a._eo_ptr();
+}
+
+EFL_START_TEST(eolian_cxx_test_wrapper_converts_to_base)
+{
+ efl::eo::eo_init init;
+
+ /* Real objects: a default constructed wrapper holds no Eo and would make
+ * every comparison below trivially equal. */
+ nonamespace::C c_obj(efl::eo::instantiate);
+ fail_if(c_obj._eo_ptr() == nullptr);
+ nonamespace::C const& c_const = c_obj;
+ nonamespace::B const& b_const = c_obj;
+
+ fail_if(take_base(c_const) != c_obj._eo_ptr());
+ fail_if(take_base(c_obj) != c_obj._eo_ptr());
+ fail_if(take_base(b_const) != c_obj._eo_ptr());
+
+ nonamespace::C c_temp(efl::eo::instantiate);
+ Eo* temp_ptr = c_temp._eo_ptr();
+ fail_if(take_base(std::move(c_temp)) != temp_ptr);
+ fail_if(take_base(nonamespace::C(efl::eo::instantiate)) == nullptr);
+
+ nonamespace::A const& r = c_const;
+ fail_if(r._eo_ptr() != c_obj._eo_ptr());
+}
+EFL_END_TEST
+
void
eolian_cxx_test_wrapper(TCase* tc)
{
tcase_add_test(tc, eolian_cxx_test_wrapper_size);
+ tcase_add_test(tc, eolian_cxx_test_wrapper_converts_to_base);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.