https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104111
Bug ID: 104111
Summary: Concept evaluation depends on context where it was
first checked
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
Please consider a concept and a class definitions:
```
template<class T>
concept has_private = requires(){ &T::private_;};
class B{
int private_;
friend class A;
};
```
If we first check the concept inside `A` then it will be always evaluated to
true:
```
class A{
static_assert( has_private<B> );
};
static_assert( has_private<B> );
```
Demo: https://godbolt.org/z/eYP6Tq7Y7
But if we first check the concept outside `A` then it will be always evaluated
to false:
```
static_assert( !has_private<B> );
class A{
static_assert( !has_private<B> );
};
```
Demo: https://godbolt.org/z/vsTx4oTaE
Clang has the same behavior. At the same time MSVC always evaluates the concept
to false, and it looks correct, because context evaluation shall not depend on
the context.
Related discussion: https://godbolt.org/z/vsTx4oTaE