This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

g++ extension for Concepts TS


Hey all,

I've been working on a concept extension that permits type aliases
inside the requires-seq.
The grammar addition is fairly simple.

```
requirement-seq
   requirement
   alias-declaration
   requirement-seq requirement
```

Semantically, this change forces a requirement-body to open a new
scope to house the alias.

I've managed to get it working for variable concepts, but not function concepts.

It looks like type aliases for some concepts are tricking the compiler
into thinking that there are multiple statements.
For example:

```cpp
template <typename T>
concept bool Foo =
requires(T a) {
   using type = T;
   using value_type = typename std::vector<T>::value_type;
   {a + a} -> value_type;
   {a - a} -> type;
   {a + a} -> typename std::vector<T>::value_type;
   {a - a} -> T;
};
```
works, but

```cpp
template <typename T>
concept bool Foo() {
requires(T a) {
   using type = T;
   using value_type = typename std::vector<T>::value_type;
   {a + a} -> value_type;
   {a - a} -> type;
   {a + a} -> typename std::vector<T>::value_type;
   {a - a} -> T;
};
}
```
fails with

```
test.cpp: In function 'concept bool Foo()':
test.cpp:4:14: error: definition of concept 'concept bool Foo()' has
multiple statements
 concept bool Foo() {
              ^~~
test.cpp: In function 'int main()':
test.cpp:17:10: error: deduced initializer does not satisfy
placeholder constraints
  Foo i = 0;
          ^
test.cpp:17:10: note: in the expansion of concept '(Foo<auto>)()'
template<class T> concept bool Foo() [with T = int]
```

After some inspection, I've deduced that the issue is flagged in
constraint.cc:2527, where a DECL_EXPR is identified, instead of a
RETURN_EXPR.
I'm wondering if it's trivially possible to ignore these declarations?
E.g. a loop that somewhat resembles:

```cpp
while (body != TREE_NULL && TREE_CODE(STATEMENT_LIST_HEAD(body)) ==
DECL_EXPR && is also an alias declaration)
   body = STATEMENT_LIST_TAIL(body);
if (body != TREE_NULL)
  error...
// else cleared of all charges
```

Cheers,

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]