public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gcc@arne-mertz.de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/108966] New: Inheriting consteval constructor makes it constexpr in the derived class
Date: Tue, 28 Feb 2023 10:34:35 +0000	[thread overview]
Message-ID: <bug-108966-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108966
           Summary: Inheriting consteval constructor makes it constexpr in
                    the derived class
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc@arne-mertz.de
  Target Milestone: ---

Consider the following code:
```
struct X
{
    consteval X(int) {};
};

struct T : X
{
    using X::X;
};

constexpr T t(22);
```

The using directive (1) should lead to a `consteval T::T(int)`. However, the
compiler errors with message 

```
<source>: In constructor 'constexpr T::T(double&&) [inherited from X]':
<source>:8:14: error: 'this' is not a constant expression
   8 |     using X::X;
```

This indicates that the inherited constructor is considered `constexpr` instead
of `consteval` and is therefore unable to call the `consteval` base class
constructor.

See it in action: https://godbolt.org/z/K6T6f1691

Note: 
- this does not happen when the constructor is replaced with `X::X() = default`
and no initializer is given to `t`, but a similar error appears with `X::X()
{}`

             reply	other threads:[~2023-02-28 10:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 10:34 gcc@arne-mertz.de [this message]
2023-02-28 17:10 ` [Bug c++/108966] " ppalka 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-108966-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).