https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109397
Bug ID: 109397
Summary: [concepts] Unexpected "satisfaction of atomic
constraint ... depends on itself"
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: catsith at me dot com
Target Milestone: ---
Created attachment 54805
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54805&action=edit
.ii file from -save-temps
Please help me understand if it's a bug in GCC or my code (which Clang
accepts).
bug.ii attached; bug.cpp and compiler output follows:
template<typename _type, typename _stream>
concept streamable = requires(_stream &s, _type &&v) {
s << static_cast<_type &&>(v);
};
struct type_a {
template<typename _arg>
type_a &operator<<(_arg &&) {
// std::clog << "type_a" << std::endl;
return *this;
}
};
struct type_b {
type_b &operator<<(type_a const &) {
// std::clog << "type_b" << std::endl;
return *this;
}
};
struct type_c {
type_b b;
template<typename _arg>
requires streamable<_arg, type_b>
friend type_c &operator<<(type_c &c, _arg &&a) {
// std::clog << "type_c" << std::endl;
c.b << static_cast<_arg &&>(a);
return c;
}
};
int main() {
type_a a;
type_c c;
a << c; // "type_a\n" (gcc gives error here)
c << a; // "type_c\ntype_b\n"
}
$ docker run --rm -ti -v $(pwd):/root gcc g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-linux-gnu/12.2.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: /usr/src/gcc/configure --build=x86_64-linux-gnu
--disable-multilib --enable-languages=c,c++,fortran,go
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (GCC)
$ docker run --rm -ti -v $(pwd):/root gcc g++ -std=c++2b -Wall -Wextra
-save-temps /root/bug.cpp -o /root/bug
/root/bug.cpp: In substitution of 'template<class _arg> requires
streamable<_arg, type_b> type_c& operator<<(type_c&, _arg&&) [with _arg =
type_c&]':
/root/bug.cpp:3:5: required by substitution of 'template<class _arg>
requires streamable<_arg, type_b> type_c& operator<<(type_c&, _arg&&) [with
_arg = type_c&]'
/root/bug.cpp:35:8: required from here
/root/bug.cpp:2:9: required for the satisfaction of 'streamable<_arg,
type_b>' [with _arg = type_c&]
/root/bug.cpp:2:22: in requirements with '_stream& s', '_type&& v' [with
_type = type_c&; _stream = type_b]
/root/bug.cpp:2:22: error: satisfaction of atomic constraint 'requires(_stream&
s, _type&& v) {s << static_cast<_type&&>(v);} [with _type = _arg; _stream =
type_b]' depends on itself
2 | concept streamable = requires(_stream &s, _type &&v) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 | s << static_cast<_type &&>(v);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 | };
| ~
Thank you.