https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108570
Bug ID: 108570 Summary: [concept] GCC tries to instantiate additional unneeded operator. Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fsb4000 at yandex dot ru Target Milestone: --- Hello! Look at the code: ```c++ template <class T> concept Foo = requires(T val) { val == val; }; template <class T> struct Bar {}; template <class T> bool operator==(const Bar<T>&, const Bar<T>&); template <class T> requires Foo<Bar<T>> bool operator==(const Bar<T>&, int); static_assert(Foo<Bar<int>>); ``` $ g++ -std=c++20 test.cpp test.cpp: In substitution of 'template<class T> requires Foo<Bar<T> > bool operator==(const Bar<T>&, int) [with T = int]': test.cpp:3:7: required from here test.cpp:2:9: required for the satisfaction of 'Foo<Bar<T> >' [with T = int] test.cpp:2:15: in requirements with 'T val' [with T = Bar<int>] test.cpp:2:15: error: satisfaction of atomic constraint 'requires(T val) {val == val;} [with T = Bar<int>]' depends on itself 2 | concept Foo = requires(T val) { | ^~~~~~~~~~~~~~~~~ 3 | val == val; | ~~~~~~~~~~~ 4 | }; | ~ test.cpp: In substitution of 'template<class T> requires Foo<Bar<T> > bool operator==(const Bar<T>&, int) [with T = int]': test.cpp:3:7: required from here test.cpp:2:9: required for the satisfaction of 'Foo<Bar<T> >' [with T = int] test.cpp:2:15: in requirements with 'T val' [with T = Bar<int>] test.cpp:2:15: error: satisfaction of atomic constraint 'requires(T val) {val == val;} [with T = Bar<int>]' depends on itself $ g++ -v Using built-in specs. COLLECT_GCC=C:\tools\msys64\mingw64\bin\g++.exe COLLECT_LTO_WRAPPER=C:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../gcc-12.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-libstdcxx-debug --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++ Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.0 (Rev1, Built by MSYS2 project MSVC and clang++ can compile the code. Do you think this is GCC bug or MSVC and clang++ are too permissive? Found by hui.xie1...@gmail.com and varco...@apple.com while implementing zip_iterator Godbolt link: https://godbolt.org/z/ff41PE9KG