public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103540] New: diagnosting concept depends on itself
@ 2021-12-03 14:05 ich.freak at gmx dot net
  2021-12-03 22:10 ` [Bug c++/103540] " redi at gcc dot gnu.org
  2021-12-05 16:04 ` ich.freak at gmx dot net
  0 siblings, 2 replies; 3+ messages in thread
From: ich.freak at gmx dot net @ 2021-12-03 14:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103540
           Summary: diagnosting concept depends on itself
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ich.freak at gmx dot net
  Target Milestone: ---

When a concept X is checked for a template parameter T, this parameter is fully
instanciated.
(while this may not be necessary to check the concept, this seems to be
dictated by the standard if I understood correctly)
If the instanciation of T depends on the concept X<T>, then gcc refuses to
compile the code saying something like
"satisfaction of atomic constraint X<T> depends on itself".
If T is large, however, it may be very difficult to determine where exactly T
depends on X<T> and gcc currently does not help at all to find the problem.
It would be nice if gcc could tell the reader something like "X<T> depends on
itself because the type T::something declared in line Z depends on X<T>"

I prepared a small example here <https://godbolt.org/z/q9KczYb16>. Note that
diagnostics end with

<source>:5:14: note: the required type 'typename N::something' is invalid,
because
    5 |     typename N::something;
      |     ~~~~~~~~~^~~~~~~~~~~~~
Compiler returned: 1

leaving the reader to wonder "because of what?"

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/103540] diagnosting concept depends on itself
  2021-12-03 14:05 [Bug c++/103540] New: diagnosting concept depends on itself ich.freak at gmx dot net
@ 2021-12-03 22:10 ` redi at gcc dot gnu.org
  2021-12-05 16:04 ` ich.freak at gmx dot net
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-03 22:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Please provide the code here in bugzilla, not just a URL, as requested at
https://gcc.gnu.org/bugs/


#include <type_traits>

template<typename N>
concept StrictNodeType = requires {
    typename N::something;
};

template<StrictNodeType N> using Int = int; 

template<int>
struct X {using something = Int<X>; };

using ThisBreaks = Int<X<0>>;



As well as the "depends on itself" error and the incomplete "because" note,
there is an error pointing to exactly the right spot already:

<source>:11:17: error: template constraint failure for 'template<class N> 
requires  StrictNodeType<N> using Int = int'
   11 | struct X {using something = Int<X>; };
      |                 ^~~~~~~~~

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/103540] diagnosting concept depends on itself
  2021-12-03 14:05 [Bug c++/103540] New: diagnosting concept depends on itself ich.freak at gmx dot net
  2021-12-03 22:10 ` [Bug c++/103540] " redi at gcc dot gnu.org
@ 2021-12-05 16:04 ` ich.freak at gmx dot net
  1 sibling, 0 replies; 3+ messages in thread
From: ich.freak at gmx dot net @ 2021-12-05 16:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Igel <ich.freak at gmx dot net> ---
Ah thanks for copying the relevant code here. The error that you're referring
to is:

<source>: In instantiation of 'struct X<0>':
<source>:5:14:   required by substitution of 'template<class N>  requires 
StrictNodeType<N> using Int = int [with N = X<0>]'
<source>:15:27:   required from here
<source>:12:11: error: template constraint failure for 'template<class N> 
requires  StrictNodeType<N> using Int = int'
   12 |     using something = Int<X>;
      |           ^~~~~~~~~
<source>:12:11: note: constraints not satisfied


I guess technically, you're right that it points to the correct spot and it is
the programmers duty to translate this into
"the concept StrictNodeType<X<0>> depends on itself because the type
X<0>::something (also known as Int<X<0>>) declared in line 12 depends on the
concept StrictNodeType<X<0>>".
However, this information can be buried arbitrarily deep in the error messages.
Consider, for example, the following adaptation:

#include <type_traits>

template<typename N>
concept StrictNodeType = requires {
    typename N::something;
};

template<StrictNodeType N> using Int = int; 

template<template<class> class P, class Q>
using chooser = P<Q>;

template<int>
struct X { using something = chooser<Int, X>; };

using ThisBreaks = Int<X<0>>;


The only hint towards the real problem (gcc cannot tell if X<0> has a type
called 'something' or not) is now this:
<source>:14:18:   required from 'struct X<0>'

I guess all I'm saying is that extracting the site of the problematic code is
currently very hard for "depends on itself"-errors.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-05 16:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 14:05 [Bug c++/103540] New: diagnosting concept depends on itself ich.freak at gmx dot net
2021-12-03 22:10 ` [Bug c++/103540] " redi at gcc dot gnu.org
2021-12-05 16:04 ` ich.freak at gmx dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).