public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hr.jonas.hansen at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/108536] New: Difference when using requires and enable_if with class constructor
Date: Wed, 25 Jan 2023 09:44:48 +0000	[thread overview]
Message-ID: <bug-108536-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108536
           Summary: Difference when using requires and enable_if with
                    class constructor
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hr.jonas.hansen at gmail dot com
  Target Milestone: ---

In the code below I have used a requires-clause. This requires-clause used to
be an enable_if. When using enable_if the code compiles without errors, but
using the requires-clause (see below) causes a compilation error when combined
with the rest of the example. That is, the example contains two classes ClassA
and ClassB. If either of the classes ClassA and ClassB are removed then the
code compiles without errors.


Compile with: g++ -std=c++20 example.cpp



#include <type_traits>

struct Base {
    Base() noexcept = default;

    template <typename F, typename DecayF = std::decay_t<F>>
    // If this requires-clause is replaces with an enable_if then the code
compiles fine
        requires(!std::is_same_v<DecayF, Base>
                 && std::is_constructible_v<DecayF, F>)
    Base(F&&) {}
};

struct Derived : public Base {
    using Base::Base;
    void operator()() const;
};

class ClassA {
    // The class ClassB must be present for the bug to manifest
    class ClassB;

    // This is the only usage of 'Derived'
    Derived const f;
};

// This class and its contructor must be included for the bug to manifest
class ClassA::ClassB {
    ClassB();
};

             reply	other threads:[~2023-01-25  9:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25  9:44 hr.jonas.hansen at gmail dot com [this message]
2023-01-25 10:40 ` [Bug c++/108536] " redi at gcc dot gnu.org
2023-01-25 11:21 ` hr.jonas.hansen at gmail dot com
2023-01-25 11:45 ` redi at gcc dot gnu.org
2023-01-25 16:42 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108536-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).