[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

Stephan Bergmann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 3 03:07:32 PDT 2023


sberg added a comment.

Since this commit (plus its follow-up https://github.com/llvm/llvm-project/commit/ce861ec782ae3f41807b61e855512aaccf3c2149 "[Clang][Sema] Add a temporary workaround in SemaConcept.cpp", to avoid `clang/lib/AST/ExprConstant.cpp:15332: bool clang::Expr::EvaluateAsConstantExpr(EvalResult &, const ASTContext &, ConstantExprKind) const: Assertion `!isValueDependent() && "Expression evaluator can't be called on a dependent expression."' failed` in `-DLLVM_ENABLE_ASSERTIONS=ON` builds):

  $ cat test.cc
  #include <memory>
  #include <utility>
  #include <vector>
  std::vector<std::unique_ptr<int>> v1;
  std::vector<std::unique_ptr<int>> v2;
  void f() {
    v2.insert(v2.end(), std::make_move_iterator(v1.begin()), std::make_move_iterator(v1.end()));
  }

  $ clang++ -std=c++20 -fsyntax-only test.cc
  In file included from test.cc:1:
  In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/memory:66:
  In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_tempbuf.h:61:
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_construct.h:115:4: error: no matching function for call to 'construct_at'
            std::construct_at(__p, std::forward<_Args>(__args)...);
            ^~~~~~~~~~~~~~~~~
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:120:11: note: in instantiation of function template specialization 'std::_Construct<std::unique_ptr<int>, std::unique_ptr<int> &>' requested here
              std::_Construct(std::__addressof(*__cur), *__first);
                   ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:371:14: note: in instantiation of function template specialization 'std::__do_uninit_copy<std::move_iterator<std::unique_ptr<int> *>, std::unique_ptr<int> *>' requested here
          return std::__do_uninit_copy(__first, __last, __result);
                      ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:384:19: note: in instantiation of function template specialization 'std::__uninitialized_copy_a<std::move_iterator<std::unique_ptr<int> *>, std::unique_ptr<int> *, std::unique_ptr<int>>' requested here
        return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
                    ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/vector.tcc:766:12: note: in instantiation of function template specialization 'std::__uninitialized_move_a<std::unique_ptr<int> *, std::unique_ptr<int> *, std::allocator<std::unique_ptr<int>>>' requested here
                      std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
                           ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_vector.h:1481:4: note: in instantiation of function template specialization 'std::vector<std::unique_ptr<int>>::_M_range_insert<std::move_iterator<__gnu_cxx::__normal_iterator<std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>>>' requested here
            _M_range_insert(begin() + __offset, __first, __last,
            ^
  test.cc:7:6: note: in instantiation of function template specialization 'std::vector<std::unique_ptr<int>>::insert<std::move_iterator<__gnu_cxx::__normal_iterator<std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>>, void>' requested here
    v2.insert(v2.end(), std::make_move_iterator(v1.begin()), std::make_move_iterator(v1.end()));
       ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_construct.h:94:5: note: candidate template ignored: substitution failure [with _Tp = std::unique_ptr<int>, _Args = <std::unique_ptr<int> &>]: call to deleted constructor of 'std::unique_ptr<int>'
      construct_at(_Tp* __location, _Args&&... __args)
      ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_construct.h:119:25: error: call to deleted constructor of 'std::unique_ptr<int>'
        ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
                          ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/unique_ptr.h:522:7: note: 'unique_ptr' has been explicitly marked deleted here
        unique_ptr(const unique_ptr&) = delete;
        ^
  In file included from test.cc:1:
  In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/memory:69:
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:120:6: error: no matching function for call to '_Construct'
              std::_Construct(std::__addressof(*__cur), *__first);
              ^~~~~~~~~~~~~~~
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:371:14: note: in instantiation of function template specialization 'std::__do_uninit_copy<std::move_iterator<__gnu_cxx::__normal_iterator<std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>>, std::unique_ptr<int> *>' requested here
          return std::__do_uninit_copy(__first, __last, __result);
                      ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/vector.tcc:781:12: note: in instantiation of function template specialization 'std::__uninitialized_copy_a<std::move_iterator<__gnu_cxx::__normal_iterator<std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>>, std::unique_ptr<int> *, std::unique_ptr<int>>' requested here
                      std::__uninitialized_copy_a(__mid, __last,
                           ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_vector.h:1481:4: note: in instantiation of function template specialization 'std::vector<std::unique_ptr<int>>::_M_range_insert<std::move_iterator<__gnu_cxx::__normal_iterator<std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>>>' requested here
            _M_range_insert(begin() + __offset, __first, __last,
            ^
  test.cc:7:6: note: in instantiation of function template specialization 'std::vector<std::unique_ptr<int>>::insert<std::move_iterator<__gnu_cxx::__normal_iterator<std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>>, void>' requested here
    v2.insert(v2.end(), std::make_move_iterator(v1.begin()), std::make_move_iterator(v1.end()));
       ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_construct.h:109:5: note: candidate template ignored: substitution failure [with _Tp = std::unique_ptr<int>, _Args = <std::unique_ptr<int> &>]
      _Construct(_Tp* __p, _Args&&... __args)
      ^
  In file included from test.cc:1:
  In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/memory:69:
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:90:21: error: static assertion failed due to requirement 'is_constructible<std::unique_ptr<int, std::default_delete<int>>, std::unique_ptr<int, std::default_delete<int>> &>::value': result type must be constructible from input type
        static_assert(is_constructible<_ValueType, _Tp>::value,
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:182:4: note: in instantiation of function template specialization 'std::__check_constructible<std::unique_ptr<int>, std::unique_ptr<int> &>' requested here
          = _GLIBCXX_USE_ASSIGN_FOR_INIT(_ValueType2, _From);
            ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:101:13: note: expanded from macro '_GLIBCXX_USE_ASSIGN_FOR_INIT'
      && std::__check_constructible<T, U>()
              ^
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:373:19: note: in instantiation of function template specialization 'std::uninitialized_copy<std::move_iterator<std::unique_ptr<int> *>, std::unique_ptr<int> *>' requested here
        return std::uninitialized_copy(__first, __last, __result);
                    ^
  4 errors generated.

(When building against `libstdc++-devel-13.1.1-1.fc38.x86_64` at least, but also when building against a GCC trunk libstdc++.  And compilation succeeds with both GCC and older Clang, so it looks like an issue with this commit rather than with the used libstdc++.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146178/new/

https://reviews.llvm.org/D146178



More information about the cfe-commits mailing list