public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108536] New: Difference when using requires and enable_if with class constructor
@ 2023-01-25  9:44 hr.jonas.hansen at gmail dot com
  2023-01-25 10:40 ` [Bug c++/108536] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hr.jonas.hansen at gmail dot com @ 2023-01-25  9:44 UTC (permalink / raw)
  To: gcc-bugs

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();
};

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

end of thread, other threads:[~2023-01-25 16:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25  9:44 [Bug c++/108536] New: Difference when using requires and enable_if with class constructor hr.jonas.hansen at gmail dot com
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

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