Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build: use of deleted function #14

Open
andviane opened this issue Apr 20, 2020 · 2 comments
Open

Unable to build: use of deleted function #14

andviane opened this issue Apr 20, 2020 · 2 comments

Comments

@andviane
Copy link

Looks like a great thing but unfortunately I cannot build it:

[ 28%] Building CXX object examples/CMakeFiles/lowercase.dir/lowercase.cpp.o
In file included from /home/audrius/projects/lru_cache/lru-cache/include/lru/internal/base-cache.hpp:37:0,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/cache.hpp:36,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/lru.hpp:26,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/lowercase.hpp:25,
                 from /home/audrius/projects/lru_cache/lru-cache/examples/lowercase.cpp:25:
/home/audrius/projects/lru_cache/lru-cache/include/lru/internal/base-ordered-iterator.hpp: In instantiation of ‘LRU::Internal::BaseOrderedIterator<Key, Value, Cache>::BaseOrderedIterator(LRU::Internal::BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator>&&) [with AnyCache = LRU::Internal::BaseCache<int, int, LRU::Internal::Information, std::hash<int>, std::equal_to<int>, LRU::Tag::BasicCache>; UnderlyingIterator = std::__detail::_Node_iterator<std::pair<const int, LRU::Internal::Information<int, int> >, false, false>; <template-parameter-2-3> = void; Key = const int; Value = const int; Cache = const LRU::Internal::BaseCache<int, int, LRU::Internal::Information, std::hash<int>, std::equal_to<int>, LRU::Tag::BasicCache>]’:
/home/audrius/projects/lru_cache/lru-cache/include/lru/internal/base-cache.hpp:311:42:   required from ‘LRU::Internal::BaseCache<Key, Value, InformationType, HashFunction, KeyEqual, TagType>::OrderedConstIterator::OrderedConstIterator(LRU::Internal::BaseCache<Key, Value, InformationType, HashFunction, KeyEqual, TagType>::UnorderedIterator) [with Key = int; Value = int; InformationType = LRU::Internal::Information; HashFunction = std::hash<int>; KeyEqual = std::equal_to<int>; TagType = LRU::Tag::BasicCache]’
/home/audrius/projects/lru_cache/lru-cache/examples/lowercase.cpp:44:70:   required from here
/home/audrius/projects/lru_cache/lru-cache/include/lru/internal/base-ordered-iterator.hpp:128:12: error: use of deleted function ‘std::optional<LRU::Entry<const int, const int> >& std::optional<LRU::Entry<const int, const int> >::operator=(std::optional<LRU::Entry<const int, const int> >&&)’
     _entry = std::move(unordered_iterator._entry);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/node_handle.h:39:0,
                 from /usr/include/c++/7/bits/hashtable.h:37,
                 from /usr/include/c++/7/unordered_map:47,
                 from /usr/include/c++/7/functional:60,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/cache.hpp:28,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/lru.hpp:26,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/lowercase.hpp:25,
                 from /home/audrius/projects/lru_cache/lru-cache/examples/lowercase.cpp:25:
/usr/include/c++/7/optional:453:11: note: ‘std::optional<LRU::Entry<const int, const int> >& std::optional<LRU::Entry<const int, const int> >::operator=(std::optional<LRU::Entry<const int, const int> >&&)’ is implicitly deleted because the default definition would be ill-formed:
     class optional
           ^~~~~~~~
/usr/include/c++/7/optional:453:11: error: use of deleted function ‘std::_Enable_copy_move<true, false, true, false, _Tag>& std::_Enable_copy_move<true, false, true, false, _Tag>::operator=(std::_Enable_copy_move<true, false, true, false, _Tag>&&) [with _Tag = std::optional<LRU::Entry<const int, const int> >]’
In file included from /usr/include/c++/7/optional:43:0,
                 from /usr/include/c++/7/bits/node_handle.h:39,
                 from /usr/include/c++/7/bits/hashtable.h:37,
                 from /usr/include/c++/7/unordered_map:47,
                 from /usr/include/c++/7/functional:60,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/cache.hpp:28,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/lru.hpp:26,
                 from /home/audrius/projects/lru_cache/lru-cache/include/lru/lowercase.hpp:25,
                 from /home/audrius/projects/lru_cache/lru-cache/examples/lowercase.cpp:25:
/usr/include/c++/7/bits/enable_special_members.h:246:5: note: declared here
     operator=(_Enable_copy_move&&) noexcept                         = delete;
     ^~~~~~~~
examples/CMakeFiles/lowercase.dir/build.make:62: recipe for target 'examples/CMakeFiles/lowercase.dir/lowercase.cpp.o' failed
make[2]: *** [examples/CMakeFiles/lowercase.dir/lowercase.cpp.o] Error 1
CMakeFiles/Makefile2:294: recipe for target 'examples/CMakeFiles/lowercase.dir/all' failed
make[1]: *** [examples/CMakeFiles/lowercase.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2

I tried to force C++17 and C++14 in CMakeLists.txt but was not helpful

My compiler:

gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
cmake --version
cmake version 3.16.0
make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu

Let me known what else. I would be happy to assist in testing.

@andviane andviane changed the title Unable to build Unable to build: use of deleted function ‘std::optional<LRU::Entry<const int, const int> >& std::optional<LRU::Entry<const int, const int> >::operator=(std::optional<LRU::Entry<const int, const int> >&&)’ Apr 20, 2020
@andviane andviane changed the title Unable to build: use of deleted function ‘std::optional<LRU::Entry<const int, const int> >& std::optional<LRU::Entry<const int, const int> >::operator=(std::optional<LRU::Entry<const int, const int> >&&)’ Unable to build: use of deleted function ‘std::optional<LRU::Entry ... operator= .. ’ Apr 20, 2020
@andviane andviane changed the title Unable to build: use of deleted function ‘std::optional<LRU::Entry ... operator= .. ’ Unable to build: use of deleted function Apr 20, 2020
@OdyX
Copy link

OdyX commented Jun 12, 2023

I can confirm this is still the case some years later:

git clone https://github.com/goldsborough/lru-cache
cd lru-cache
git submodule update --init
cmake . -B build
cd build
make lowercase

Results in:

[ 50%] Building CXX object examples/CMakeFiles/lowercase.dir/lowercase.cpp.o
In file included from /tmp/lru-cache/include/lru/internal/base-ordered-iterator.hpp:32,
                 from /tmp/lru-cache/include/lru/internal/base-cache.hpp:37,
                 from /tmp/lru-cache/include/lru/cache.hpp:36,
                 from /tmp/lru-cache/include/lru/lru.hpp:26,
                 from /tmp/lru-cache/include/lru/lowercase.hpp:25,
                 from /tmp/lru-cache/examples/lowercase.cpp:25:
/tmp/lru-cache/include/lru/internal/base-iterator.hpp:63:34: warning: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> struct std::iterator' is deprecated [-Wdeprecated-declarations]
   63 | class BaseIterator : public std::iterator<IteratorTag, LRU::Entry<Key, Value>> {
      |                                  ^~~~~~~~
In file included from /usr/include/c++/12/string:45,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/iostream:39,
                 from /tmp/lru-cache/examples/lowercase.cpp:23:
/usr/include/c++/12/bits/stl_iterator_base_types.h:127:34: note: declared here
  127 |     struct _GLIBCXX17_DEPRECATED iterator
      |                                  ^~~~~~~~
/tmp/lru-cache/include/lru/internal/base-ordered-iterator.hpp: In instantiation of 'LRU::Internal::BaseOrderedIterator<Key, Value, Cache>::BaseOrderedIterator(LRU::Internal::BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator>&&) [with AnyCache = LRU::Internal::BaseCache<int, int, LRU::Internal::Information, std::hash<int>, std::equal_to<int>, LRU::Tag::BasicCache>; UnderlyingIterator = std::__detail::_Node_iterator<std::pair<const int, LRU::Internal::Information<int, int> >, false, false>; <template-parameter-2-3> = void; Key = const int; Value = const int; Cache = const LRU::Internal::BaseCache<int, int, LRU::Internal::Information, std::hash<int>, std::equal_to<int>, LRU::Tag::BasicCache>]':
/tmp/lru-cache/include/lru/internal/base-cache.hpp:311:42:   required from 'LRU::Internal::BaseCache<Key, Value, InformationType, HashFunction, KeyEqual, TagType>::OrderedConstIterator::OrderedConstIterator(LRU::Internal::BaseCache<Key, Value, InformationType, HashFunction, KeyEqual, TagType>::UnorderedIterator) [with Key = int; Value = int; InformationType = LRU::Internal::Information; HashFunction = std::hash<int>; KeyEqual = std::equal_to<int>; TagType = LRU::Tag::BasicCache]'
/tmp/lru-cache/examples/lowercase.cpp:44:70:   required from here
/tmp/lru-cache/include/lru/internal/base-ordered-iterator.hpp:128:12: error: use of deleted function 'std::optional<LRU::Entry<const int, const int> >& std::optional<LRU::Entry<const int, const int> >::operator=(std::optional<LRU::Entry<const int, const int> >&&)'
  128 |     _entry = std::move(unordered_iterator._entry);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /tmp/lru-cache/include/lru/internal/optional.hpp:29,
                 from /tmp/lru-cache/include/lru/internal/base-iterator.hpp:29:
/usr/include/c++/12/optional:705:11: note: 'std::optional<LRU::Entry<const int, const int> >& std::optional<LRU::Entry<const int, const int> >::operator=(std::optional<LRU::Entry<const int, const int> >&&)' is implicitly deleted because the default definition would be ill-formed:
  705 |     class optional
      |           ^~~~~~~~
/usr/include/c++/12/optional:705:11: error: use of deleted function 'std::_Enable_copy_move<true, false, true, false, _Tag>& std::_Enable_copy_move<true, false, true, false, _Tag>::operator=(std::_Enable_copy_move<true, false, true, false, _Tag>&&) [with _Tag = std::optional<LRU::Entry<const int, const int> >]'
In file included from /usr/include/c++/12/bits/hashtable.h:36,
                 from /usr/include/c++/12/unordered_map:46,
                 from /usr/include/c++/12/functional:61,
                 from /tmp/lru-cache/include/lru/cache.hpp:28:
/usr/include/c++/12/bits/enable_special_members.h:249:5: note: declared here
  249 |     operator=(_Enable_copy_move&&) noexcept                         = delete;
      |     ^~~~~~~~
make[3]: *** [examples/CMakeFiles/lowercase.dir/build.make:76: examples/CMakeFiles/lowercase.dir/lowercase.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:283: examples/CMakeFiles/lowercase.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:290: examples/CMakeFiles/lowercase.dir/rule] Error 2
make: *** [Makefile:231: lowercase] Error 2

This, on a (very) recent Debian bookworm, but I can reproduce this easily in a Debian Buster (from 2019).

@davesrocketshop
Copy link

I encountered this issue in my own use of the LRU cache. The problem isn't in the LRU code per se, but in the underlying classes.

In my case I was attempting to use the code in a Qt based application. My cache was defined as:

LRU::Cache<QString, std::shared_ptr<MyObject>> _cache;

This build fine on Ubuntu 24.04 and 22.04, but not 20.04. Researching a little it showed the problem is likely caused by a missing move constructor, which makes sense given the older libraries in 20.04. I changed the key from QString to std::sting and everything built fine.

I haven't looked at the provided example code, but I wouldn't be surprised if it's something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants