Skip to content

test errors: ambiguous overload for ‘operator=’, binding reference discards qualifiers #2887

Open

Description

@drew-parsons

I'm trying to build xtensor 0.27.1 with xtl 0.8.1 (on a debian linux system).

Build-time tests (with g++) are passing, but runtime tests (tests subdir) using the installed packages are failing with both g++ 15.2.0 and clang 21.1.8.

g++ reports

[ 73%] Building CXX object CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o
/usr/bin/g++   -DXSIMD_ENABLE_XTL_COMPLEX=1 -march=native -std=c++20 -Wunused-parameter -Wextra -Wreorder -Wconversion -Wno-sign-conversion  -Wold-style-cast -Wunused-variable -ftemplate-backtrace-limit=0 -O3 -D
NDEBUG -std=gnu++20 -MD -MT CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o -MF CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o.d -o CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o -c /tm
p/autopkgtest.bfBHFS/autopkgtest_tmp/test_xmasked_view.cpp
...
In file included from /usr/include/xtensor/core/xsemantic.hpp:16,
                 from /usr/include/xtensor/views/xstrided_view.hpp:26,
                 from /usr/include/xtensor/core/xoperation.hpp:22,
                 from /usr/include/xtensor/core/xmath.hpp:28,
                 from /usr/include/xtensor/io/xio.hpp:22,
                 from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xmasked_view.cpp:10:
/usr/include/xtensor/core/xassign.hpp: In instantiation of ‘void xt::stepper_assigner<E1, E2, L>::run() [with E1 = xt::xmasked_view<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_t
ype::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&, xt::xarray_container<xt::uvector<bool, std::allocator<bool> >, xt::layout_type::row_major
, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&>; E2 = xt::xbroadcast<const xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layou
t_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true> >; xt::layo
ut_type L = xt::layout_type::row_major]’:
...
/usr/include/xtensor/views/xmasked_view.hpp:579:40:   required from ‘xt::xmasked_view<CTD, CTM>::self_type& xt::xmasked_view<CTD, CTM>::operator=(const xt::xexpression<E1>&) [with E = xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>; CTD = xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&; CTM = xt::xarray_container<xt::uvector<bool, std::allocator<bool> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&; self_type = xt::xmasked_view<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&, xt::xarray_container<xt::uvector<bool, std::allocator<bool> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&>]’
  579 |         return semantic_base::operator=(e);
      |                ~~~~~~~~~~~~~~~~~~~~~~~~^~~
/tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xmasked_view.cpp:221:23:   required from here
  221 |         masked_data = data2;
      |                       ^~~~~
/usr/include/xtensor/core/xassign.hpp:664:20: error: ambiguous overload for ‘operator=’ (operand types are ‘xt::xmasked_view_stepper<xt::xmasked_view<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&, xt::xarray_container<xt::uvector<bool, std::allocator<bool> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&>, false>::reference’ {aka ‘xtl::xmasked_value<double&, bool&>’} and ‘xtl::xmasked_value<double&, bool&>’)
  664 |             *m_lhs = conditional_cast<needs_cast, result_type>(*m_rhs);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/xtensor/core/xassign.hpp:664:20: note: there are 4 candidates
In file included from /usr/include/xtensor/views/xmasked_view.hpp:20,
                 from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xmasked_view.cpp:12:
/usr/include/xtl/xmasked_value.hpp:92:9: note: candidate 1: ‘xtl::xmasked_value<T, B>& xtl::xmasked_value<T, B>::operator=(const T1&) [with T1 = xtl::xmasked_value<double&, bool&>; T = double&; B = bool&]’
   92 |         DEFINE_ASSIGN_OPERATOR(=);
      |         ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/xtl/xmasked_value.hpp:92:9: note: candidate 2: ‘xtl::xmasked_value<T, B>& xtl::xmasked_value<T, B>::operator=(const xtl::xmasked_value<T1, B1>&) [with T1 = double&; B1 = bool&; T = double&; B = bool&]’
   92 |         DEFINE_ASSIGN_OPERATOR(=);
      |         ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/xtl/xmasked_value.hpp:30:11: note: candidate 3: ‘xtl::xmasked_value<double&, bool&>& xtl::xmasked_value<double&, bool&>::operator=(const xtl::xmasked_value<double&, bool&>&)’ (deleted)
   30 |     class xmasked_value
      |           ^~~~~~~~~~~~~
/usr/include/xtl/xmasked_value.hpp:30:11: note: candidate 4: ‘xtl::xmasked_value<double&, bool&>& xtl::xmasked_value<double&, bool&>::operator=(xtl::xmasked_value<double&, bool&>&&)’ (deleted)
/usr/include/xtensor/core/xassign.hpp: In instantiation of ‘void xt::stepper_assigner<E1, E2, L>::run() [with E1 = xt::xmasked_view<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_t
ype::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&, xt::xarray_container<xt::uvector<bool, std::allocator<bool> >, xt::layout_type::row_major
, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&>; E2 = xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt
::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>; xt::layout_type L = xt::layout_type::row_major]’:
/usr/include/xtensor/core/xassign.hpp:476:97:   required from ‘static void xt::xexpression_assigner_base<xt::xtensor_expression_tag>::assign_data(xt::xexpression<D>&, const xt::xexpression<E2>&, bool) [with E1 =
 xt::xmasked_view<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression
_tag>&, xt::xarray_container<xt::uvector<bool, std::allocator<bool> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&>; E2 = xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>]’
  476 |             stepper_assigner<E1, E2, default_assignable_layout(E1::static_layout)>(de1, de2).run();
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
...

Activity

  1. drew-parsons commented on Feb 9, 2026

    @drew-parsons
    ContributorAuthor

    Both g++ 15 and clang 21 report

    /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xmasked_view.cpp:221:23:   required from here
      221 |         masked_data = data2;
          |                       ^~~~~
    /usr/include/xtl/xmasked_value.hpp:123:11: error: binding reference of type ‘xtl::xmasked_value<double&, bool&>::value_type’ {aka ‘double&’} to ‘const double’ discards qualifiers
      123 |         : m_value(std::forward<T1>(value)), m_visible(true)
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/xtl/xmasked_value.hpp:123:55: error: cannot bind non-const lvalue reference of type ‘xtl::xmasked_value<double&, bool&>::flag_type’ {aka ‘bool&’} to an rvalue of type ‘bool’
      123 |         : m_value(std::forward<T1>(value)), m_visible(true)
          |                                                       ^~~~
    make[3]: *** [CMakeFiles/test_xtensor_lib.dir/build.make:863: CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o] Error 1
    

    That's from g++.
    The message from clang 21 is similar:

    [ 73%] Building CXX object CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o
    /usr/bin/clang++   -DXSIMD_ENABLE_XTL_COMPLEX=1 -march=native -std=c++20 -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion -Wold-style-cast -Wunused-variable -O3 -DNDEBUG -std=gnu++20 -MD -MT C
    MakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o -MF CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o.d -o CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o -c /tmp/autopkgtest.bfBHFS/autopkgt
    est_tmp/test_xmasked_view.cpp
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xio.cpp:24:
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_common_macros.hpp:10:
    In file included from /usr/include/doctest/doctest.h:499:
    /usr/lib/gcc/x86_64-linux-gnu/15/../../../../include/c++/15/ciso646:49:6: warning: "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros" [-W#warnings]
       49 | #    warning "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros"
          |      ^
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xlayout.cpp:17:
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_common.hpp:19:
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_common_macros.hpp:10:
    In file included from /usr/include/doctest/doctest.h:499:
    /usr/lib/gcc/x86_64-linux-gnu/15/../../../../include/c++/15/ciso646:49:6: warning: "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros" [-W#warnings]
       49 | #    warning "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros"
          |      ^
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xmanipulation.cpp:18:
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_common_macros.hpp:10:
    In file included from /usr/include/doctest/doctest.h:499:
    /usr/lib/gcc/x86_64-linux-gnu/15/../../../../include/c++/15/ciso646:49:6: warning: "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros" [-W#warnings]
       49 | #    warning "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros"
          |      ^
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xmasked_view.cpp:14:
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_common_macros.hpp:10:
    In file included from /usr/include/doctest/doctest.h:499:
    /usr/lib/gcc/x86_64-linux-gnu/15/../../../../include/c++/15/ciso646:49:6: warning: "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros" [-W#warnings]
       49 | #    warning "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros"
          |      ^
    In file included from /tmp/autopkgtest.bfBHFS/autopkgtest_tmp/test_xmasked_view.cpp:12:
    In file included from /usr/include/xtensor/views/xmasked_view.hpp:20:
    /usr/include/xtl/xmasked_value.hpp:123:11: error: binding reference of type 'double' to value of type 'const double' drops 'const' qualifier
      123 |         : m_value(std::forward<T1>(value)), m_visible(true)
          |           ^       ~~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/xtensor/io/../core/../core/../containers/../utils/../utils/xutils.hpp:682:20: note: in instantiation of function template specialization 'xtl::xmasked_value<double &, bool &>::xmasked_value<const double &>' requested here
      682 |             return static_cast<T>(std::forward<U>(u));
          |                    ^
    /usr/include/xtensor/io/../core/../core/../containers/../utils/../utils/xutils.hpp:697:16: note: in instantiation of function template specialization 'xt::conditional_cast_functor<true, xtl::xmasked_value<double &, bool &>>::operator()<const double &>' requested here
      697 |         return conditional_cast_functor<condition, T>()(std::forward<U>(u));
          |                ^
    /usr/include/xtensor/io/../core/../core/../views/../core/../core/xassign.hpp:664:22: note: in instantiation of function template specialization 'xt::conditional_cast<true, xtl::xmasked_value<double &, bool &>, const double &>' requested here
      664 |             *m_lhs = conditional_cast<needs_cast, result_type>(*m_rhs);
          |                      ^
    ...
    
  2. drew-parsons commented on Feb 9, 2026

    @drew-parsons
    ContributorAuthor

    The build-time tests (which pass) are compiling with

    make  -f test/CMakeFiles/test_xmasked_view.dir/build.make test/CMakeFiles/test_xmasked_view.dir/depend
    make[4]: Entering directory '/build/xtensor-0.27.1/obj-x86_64-linux-gnu'
    cd /build/xtensor-0.27.1/obj-x86_64-linux-gnu && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /build/xtensor-0.27.1 /build/xtensor-0.27.1/test /build/xtensor-0.27.1/obj-x86_64-linux-gnu /build/xtensor-0.27.1/obj-x86_64-linux-gnu/test /build/xtensor-0.27.1/obj-x86_64-linux-gnu/test/CMakeFiles/test_xmasked_view.dir/DependInfo.cmake "--color=" test_xmasked_view
    make[4]: Leaving directory '/build/xtensor-0.27.1/obj-x86_64-linux-gnu'
    make  -f test/CMakeFiles/test_xmasked_view.dir/build.make test/CMakeFiles/test_xmasked_view.dir/build
    make[4]: Entering directory '/build/xtensor-0.27.1/obj-x86_64-linux-gnu'
    [ 48%] Building CXX object test/CMakeFiles/test_xmasked_view.dir/main.cpp.o
    cd /build/xtensor-0.27.1/obj-x86_64-linux-gnu/test && /usr/bin/c++ -DXTENSOR_FORCE_TEMPORARY_MEMORY_IN_ASSIGNMENTS -I/build/xtensor-0.27.1/include -I/build/xtensor-0.27.1/obj-x86_64-linux-gnu -g -O2 -ffile-prefix-map=/build/xtensor-0.27.1=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -DXSIMD_ENABLE_XTL_COMPLEX=1 -march=native -std=c++20 -Wunused-parameter -Wextra -Wreorder -Wconversion -Wno-sign-conversion  -Wold-style-cast -Wunused-variable -ftemplate-backtrace-limit=0 -std=gnu++20 -MD -MT test/CMakeFiles/test_xmasked_view.dir/main.cpp.o -MF CMakeFiles/test_xmasked_view.dir/main.cpp.o.d -o CMakeFiles/test_xmasked_view.dir/main.cpp.o -c /build/xtensor-0.27.1/test/main.cpp
    ..
    [ 48%] Building CXX object test/CMakeFiles/test_xmasked_view.dir/test_xmasked_view.cpp.o
    cd /build/xtensor-0.27.1/obj-x86_64-linux-gnu/test && /usr/bin/c++ -DXTENSOR_FORCE_TEMPORARY_MEMORY_IN_ASSIGNMENTS -I/build/xtensor-0.27.1/include -I/build/xtensor-0.27.1/obj-x86_64-linux-gnu -g -O2 -ffile-prefix-map=/build/xtensor-0.27.1=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -DXSIMD_ENABLE_XTL_COMPLEX=1 -march=native -std=c++20 -Wunused-parameter -Wextra -Wreorder -Wconversion -Wno-sign-conversion  -Wold-style-cast -Wunused-variable -ftemplate-backtrace-limit=0 -std=gnu++20 -MD -MT test/CMakeFiles/test_xmasked_view.dir/test_xmasked_view.cpp.o -MF CMakeFiles/test_xmasked_view.dir/test_xmasked_view.cpp.o.d -o CMakeFiles/test_xmasked_view.dir/test_xmasked_view.cpp.o -c /build/xtensor-0.27.1/test/test_xmasked_view.cpp
    ...
    [ 52%] Linking CXX executable test_xmasked_view
    cd /build/xtensor-0.27.1/obj-x86_64-linux-gnu/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/test_xmasked_view.dir/link.txt --verbose=1
    /usr/bin/c++ -g -O2 -ffile-prefix-map=/build/xtensor-0.27.1=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -DXSIMD_ENABLE_XTL_COMPLEX=1 -march=native -std=c++20 -Wunused-parameter -Wextra -Wreorder -Wconversion -Wno-sign-conversion  -Wold-style-cast -Wunused-variable -ftemplate-backtrace-limit=0 -Wl,-z,relro -Wl,--dependency-file=CMakeFiles/test_xmasked_view.dir/link.d CMakeFiles/test_xmasked_view.dir/main.cpp.o CMakeFiles/test_xmasked_view.dir/test_xmasked_view.cpp.o -o test_xmasked_view
    make[4]: Leaving directory '/build/xtensor-0.27.1/obj-x86_64-linux-gnu'
    [ 52%] Built target test_xmasked_view
    ..
    [ 93%] Building CXX object test/CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o
    cd /build/xtensor-0.27.1/obj-x86_64-linux-gnu/test && /usr/bin/c++ -DXTENSOR_FORCE_TEMPORARY_MEMORY_IN_ASSIGNMENTS -I/build/xtensor-0.27.1/include -I/build/xtensor-0.27.1/obj-x86_64-linux-gnu -g -O2 -ffile-prefi
    x-map=/build/xtensor-0.27.1=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -DXSIMD_ENABLE_XTL_COMPLEX=1 -march=native -std=c+
    +20 -Wunused-parameter -Wextra -Wreorder -Wconversion -Wno-sign-conversion  -Wold-style-cast -Wunused-variable -ftemplate-backtrace-limit=0 -std=gnu++20 -MD -MT test/CMakeFiles/test_xtensor_lib.dir/test_xmasked_
    view.cpp.o -MF CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o.d -o CMakeFiles/test_xtensor_lib.dir/test_xmasked_view.cpp.o -c /build/xtensor-0.27.1/test/test_xmasked_view.cpp
    

    I'm not sure what the key difference between build-time and run-time tests is. I guess it's not the -DXTENSOR_FORCE_TEMPORARY_MEMORY_IN_ASSIGNMENTS flag.

  3. drew-parsons commented on Feb 9, 2026

    @drew-parsons
    ContributorAuthor

    The failing case compiled with -O3 -DNDEBUG instead of -g -O2 .

    The passing case added hardening compilation flags -ffile-prefix-map=/build/xtensor-0.27.1=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2

    Of those differences, -O3 instead of -O2 sounds most relevant to me. Could -O3 trigger "binding reference" errors?

  4. drew-parsons commented on Feb 9, 2026

    @drew-parsons
    ContributorAuthor

    Hmm, apparently the issue is -DXTENSOR_FORCE_TEMPORARY_MEMORY_IN_ASSIGNMENTS.

    I can reproduce the error running the compile command from the command line. Then the otherwise failing compilation step completes successfully (with -O3) if I manually add -DXTENSOR_FORCE_TEMPORARY_MEMORY_IN_ASSIGNMENTS.

    This build flag isn't being controlled explicitly in the debian build script. It's getting set by default by the toplevel CMakeLists.txt.

    My (failing) use-case here is to run the tests as standalone tests, testing the installed xtensor library. So my workaround is to set -DXTENSOR_FORCE_TEMPORARY_MEMORY_IN_ASSIGNMENTS=ON manually when running these run-time tests.

    Apart from that, what do you advise with respect to this build flag? Is xtensor expected to trigger binding reference errors if the flag not used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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