public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116492] New: inherited constructors in subclass of std::expected can not be overridden
@ 2024-08-26 22:17 mail at johslarsen dot net
  2024-08-26 22:30 ` [Bug c++/116492] inherited constructors with concept in subclass overrides constructor in subclass pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: mail at johslarsen dot net @ 2024-08-26 22:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 116492
           Summary: inherited constructors in subclass of std::expected
                    can not be overridden
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mail at johslarsen dot net
  Target Milestone: ---

Created attachment 59007
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59007&action=edit
preprocessed file

First of all, sorry I subclassed the standard library, and yes, I am perfectly
aware that this is a very bad practice. As such the important part might not be
a fix for this in particular, but that it could shed light on similar problems
elsewhere

The following code snippet compiled with gcc 12.1 (first with std::expected on
godbolt) through 14.2 (and trunk) constructs obj by calling std::expected's
constructor directly instead of the constructor defined in my_expected:

    #include <expected>

    class my_expected : public std::expected<int, const char*> {
    public:
        my_expected() : std::expected<int, const char*>::expected(42) {}
        using std::expected<int, const char*>::expected;
    };

    int main() {
        my_expected obj;
        return *obj != 42;
    }

Resulting in *obj being zero (instead of 42), and a non-zero exit value.

This only happens with the using statement, but as far as I understand the C++
documentation the derived constructor should have been used instead:

> [...] if an inherited constructor matches the signature of one of the constructors
> of Derived, it is hidden from lookup by the version found in Derived.
> https://en.cppreference.com/w/cpp/language/using_declaration

The same does not happen in clang, and in gcc with similar examples from other
classes I have tried. g++ returns no errors or warnings with -Wall -Wextra and
all the other flags you suggested. The attached preprocessed file was generated
with g++ 14.2.1 20240805

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

end of thread, other threads:[~2024-09-20 21:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-26 22:17 [Bug c++/116492] New: inherited constructors in subclass of std::expected can not be overridden mail at johslarsen dot net
2024-08-26 22:30 ` [Bug c++/116492] inherited constructors with concept in subclass overrides constructor in subclass pinskia at gcc dot gnu.org
2024-08-26 22:33 ` pinskia at gcc dot gnu.org
2024-08-26 22:35 ` pinskia at gcc dot gnu.org
2024-09-04 18:45 ` ppalka at gcc dot gnu.org
2024-09-17 15:17 ` ppalka at gcc dot gnu.org
2024-09-20 16:34 ` cvs-commit at gcc dot gnu.org
2024-09-20 21:37 ` cvs-commit at gcc dot gnu.org
2024-09-20 21:38 ` ppalka 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).