[libcxx-commits] [clang] [libcxx] [clang] Reland: Instantiate concepts with sugared template arguments (PR #101782)
Zequan Wu via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 8 15:56:30 PDT 2024
ZequanWu wrote:
This change makes the following code no longer compile:
```
#include <concepts>
#include <iterator>
template <typename T, typename It>
concept CompatibleIter = std::contiguous_iterator<It>;
template <typename T>
class span {
public:
template <typename It>
requires(CompatibleIter<T, It>)
constexpr span(It first, int count) noexcept {
}
};
void foo(int n) {
int vla[n];
span<const int> s(vla, n);
}
```
```
$ clang++ span.cpp -c -std=c++20
span.cpp:18:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
18 | int vla[n];
| ^
span.cpp:18:11: note: function parameter 'n' with unknown value cannot be used in a constant expression
span.cpp:17:14: note: declared here
17 | void foo(int n) {
| ^
span.cpp:19:19: error: no matching constructor for initialization of 'span<const int>'
19 | span<const int> s(vla, n);
| ^ ~~~~~~
span.cpp:12:13: note: candidate template ignored: constraints not satisfied [with It = int *]
12 | constexpr span(It first, int count) noexcept {
| ^
span.cpp:11:14: note: because 'CompatibleIter<const int, int *>' evaluated to false
11 | requires(CompatibleIter<T, It>)
| ^
span.cpp:5:26: note: because 'int *' does not satisfy 'contiguous_iterator'
5 | concept CompatibleIter = std::contiguous_iterator<It>;
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/iterator_concepts.h:697:35: note: because 'int *' does not satisfy 'random_access_iterator'
697 | concept contiguous_iterator = random_access_iterator<_Iter>
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/iterator_concepts.h:681:38: note: because 'int *' does not satisfy 'bidirectional_iterator'
681 | concept random_access_iterator = bidirectional_iterator<_Iter>
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/iterator_concepts.h:671:38: note: because 'int *' does not satisfy 'forward_iterator'
671 | concept bidirectional_iterator = forward_iterator<_Iter>
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/iterator_concepts.h:666:32: note: because 'int *' does not satisfy 'input_iterator'
666 | concept forward_iterator = input_iterator<_Iter>
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/iterator_concepts.h:655:30: note: because 'int *' does not satisfy 'input_or_output_iterator'
655 | concept input_iterator = input_or_output_iterator<_Iter>
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/iterator_concepts.h:635:5: note: because 'int *' does not satisfy 'weakly_incrementable'
635 | && weakly_incrementable<_Iter>;
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/iterator_concepts.h:619:36: note: because 'int *' does not satisfy 'movable'
619 | concept weakly_incrementable = movable<_Iter>
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/concepts:265:10: note: because 'assignable_from<int *&, int *>' evaluated to false
265 | && assignable_from<_Tp&, _Tp> && swappable<_Tp>;
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/concepts:143:44: note: because 'same_as<expr-type, int *&>' would be invalid
143 | { __lhs = static_cast<_Rhs&&>(__rhs) } -> same_as<_Lhs>;
| ^
span.cpp:8:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
8 | class span {
| ^~~~
span.cpp:8:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
8 | class span {
| ^~~~
1 warning and 1 error generated.
```
Can you revert it if it takes a while to fix?
https://github.com/llvm/llvm-project/pull/101782
More information about the libcxx-commits
mailing list