https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102975

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> Hmm, this is interesting:
> template<class> concept Never = false;
> template<class T> concept C = Never<typename T::type>;
> void f() {
>   struct X {
>    // using type = int;
>   };
>   static_assert(not C<X>);
> }
> 
> is able to compile. I don't know enough about C++ concepts to say if this is
> valid or not but it looks like the type is really unused in the above case
> ...
> This is different from "constexpr bool" which requires the type to be
> defined ...

Yeah, when evaluating a concept-id such as C<X> (which is done by substituting
{X} into the normal form of C), the normalization process
(https://eel.is/c++draft/temp.constr.normal) ignores arguments to unused
template parameters.

So since 'Never' doesn't use its template parameter, during normalization of C
we discard the template argument 'typename T::type' passed to Never.  The
normal form of C ends up being 'false (with empty parameter mapping)' which is
trivially satisfied for all T.  So it seems to me the warning is correct since
evaluating C<X> doesn't actually use X::type, and the alias is never otherwise
used.

(If this discarding unused template parameters of a concept is undesirable, one
can define the concept in question in a way that trivially uses its template
parameter, e.g.:

  template<class T> concept Never = requires { typename T; } && false;)

Reply via email to