public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109397] New: [concepts] Unexpected "satisfaction of atomic constraint ... depends on itself"
@ 2023-04-04  1:47 catsith at me dot com
  2023-04-04  1:55 ` [Bug c++/109397] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: catsith at me dot com @ 2023-04-04  1:47 UTC (permalink / raw)
  To: gcc-bugs

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.

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

* [Bug c++/109397] [concepts] Unexpected "satisfaction of atomic constraint ... depends on itself"
  2023-04-04  1:47 [Bug c++/109397] New: [concepts] Unexpected "satisfaction of atomic constraint ... depends on itself" catsith at me dot com
@ 2023-04-04  1:55 ` pinskia at gcc dot gnu.org
  2023-04-04  4:30 ` catsith at me dot com
  2023-04-04  5:33 ` catsith at me dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-04  1:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
See http://wg21.link/cwg2369 also

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

* [Bug c++/109397] [concepts] Unexpected "satisfaction of atomic constraint ... depends on itself"
  2023-04-04  1:47 [Bug c++/109397] New: [concepts] Unexpected "satisfaction of atomic constraint ... depends on itself" catsith at me dot com
  2023-04-04  1:55 ` [Bug c++/109397] " pinskia at gcc dot gnu.org
@ 2023-04-04  4:30 ` catsith at me dot com
  2023-04-04  5:33 ` catsith at me dot com
  2 siblings, 0 replies; 4+ messages in thread
From: catsith at me dot com @ 2023-04-04  4:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from catsith at me dot com ---
Thank you. Looks like this is a duplicate of
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99599 then. I believe I can
workaround my problem by using std::enable_if_t instead of concepts.

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

* [Bug c++/109397] [concepts] Unexpected "satisfaction of atomic constraint ... depends on itself"
  2023-04-04  1:47 [Bug c++/109397] New: [concepts] Unexpected "satisfaction of atomic constraint ... depends on itself" catsith at me dot com
  2023-04-04  1:55 ` [Bug c++/109397] " pinskia at gcc dot gnu.org
  2023-04-04  4:30 ` catsith at me dot com
@ 2023-04-04  5:33 ` catsith at me dot com
  2 siblings, 0 replies; 4+ messages in thread
From: catsith at me dot com @ 2023-04-04  5:33 UTC (permalink / raw)
  To: gcc-bugs

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

catsith at me dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from catsith at me dot com ---
Allow me to resolve this as duplicate. As per other comments, the workaround is
to use type traits and std::enable_if_t instead of concept/requires, or to
include another constraint, e.g.

  template<std::derived_from<type_c> _type_c, typename _arg>
  requires streamable<_arg, type_b>
  friend type_c &operator<<(_type_c &, _arg &&)

*** This bug has been marked as a duplicate of bug 99599 ***

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

end of thread, other threads:[~2023-04-04  5:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-04  1:47 [Bug c++/109397] New: [concepts] Unexpected "satisfaction of atomic constraint ... depends on itself" catsith at me dot com
2023-04-04  1:55 ` [Bug c++/109397] " pinskia at gcc dot gnu.org
2023-04-04  4:30 ` catsith at me dot com
2023-04-04  5:33 ` catsith at me dot com

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).