Created attachment 39934 [details] Minimal repro This TU, which should compile without errors: template<class T> T&& declval(); template<class...> using void_t = void; template<class, class = void> struct foo { static const bool value = false; }; template<class T> struct foo<T, void_t<decltype(declval<T>() - declval<T>())>> { static const bool value = true; }; struct A; #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) STATIC_ASSERT(!foo<void*>::value); // error: invalid use of 'void' STATIC_ASSERT(!foo<A*>::value); // error: invalid use of incomplete type 'struct A' instead produces diagnostics (http://melpon.org/wandbox/permlink/EwcDiz7ZuqpFXdHZ): prog.cc: In substitution of 'template<class T> struct foo<T, void_t<decltype ((declval<T>() - declval<T>()))> > [with T = void*]': prog.cc:22:1: required from here prog.cc:10:44: error: invalid use of 'void' struct foo<T, void_t<decltype(declval<T>() - declval<T>())>> { ~~~~~~~~~~~~~^~~~~~~~~~~~~~ prog.cc: In substitution of 'template<class T> struct foo<T, void_t<decltype ((declval<T>() - declval<T>()))> > [with T = A*]': prog.cc:23:1: required from here prog.cc:10:44: error: invalid use of incomplete type 'struct A' prog.cc:14:8: note: forward declaration of 'struct A' struct A; ^
This still reproduces on trunk, and in concepts land. This program fragment: template <class T> concept bool CanDifference = requires(T const& x, T const& y) { x - y; }; static_assert(!CanDifference<void*>); produces diagnostics when compiled with "g++ -std=c++2a -fconcepts" (https://godbolt.org/g/e36eFK): <source>:3:7: error: invalid use of 'void' x - y; ~~^~~
*** Bug 89300 has been marked as a duplicate of this bug. ***
*** Bug 92089 has been marked as a duplicate of this bug. ***
Looking.
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:958d42abdf1a1936d290aab126cebd6bb4a52361 commit r11-5936-g958d42abdf1a1936d290aab126cebd6bb4a52361 Author: Patrick Palka <ppalka@redhat.com> Date: Fri Dec 11 09:40:58 2020 -0500 c++: missing SFINAE with pointer subtraction [PR78173] This fixes a missed SFINAE when subtracting pointers to an incomplete type. gcc/cp/ChangeLog: PR c++/78173 * typeck.c (pointer_diff): Use complete_type_or_maybe_complain instead of complete_type_or_else. gcc/testsuite/ChangeLog: PR c++/78173 * g++.dg/cpp2a/concepts-pr78173.C: New test.
Fixed for GCC 11
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:fa452a843d26a64a5ca0fd7c17ea1bd6e1b81a69 commit r11-6074-gfa452a843d26a64a5ca0fd7c17ea1bd6e1b81a69 Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Dec 15 11:40:07 2020 +0000 libstdc++: Remove workaround for PR c++/78173 Now that the G++ bug is fixed we no longer need to protect this partial specialization from complaining about subtracting void pointers. libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (incrementable_traits<Tp>): Remove workaround for PR c++/78173.
*** Bug 87282 has been marked as a duplicate of this bug. ***