public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99495] New: constexpr virtual destructor is used before its definition
@ 2021-03-09 19:14 oleksandr.koval.dev at gmail dot com
  2021-04-24  2:38 ` [Bug c++/99495] " pdimov at gmail dot com
  2021-08-17  5:57 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: oleksandr.koval.dev at gmail dot com @ 2021-03-09 19:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99495
           Summary: constexpr virtual destructor is used before its
                    definition
           Product: gcc
           Version: 11.0
               URL: https://godbolt.org/z/GGY6aa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: oleksandr.koval.dev at gmail dot com
  Target Milestone: ---

I found this while playing with constexpr virtual functions. This code gives
"error: 'virtual constexpr Derived2::~Derived2()' used before its definition".
Error always refers to the last variable, e.g. if we swap d1 and d2
declarations, it will complain about d1. If x is decalred without constexpr it
works fine.

struct Base{
    constexpr virtual ~Base() = default;
    virtual int Get() const = 0;    // non-constexpr
};

struct Derived1 : Base{
    constexpr int Get() const override {
        return 1;
    }
};

struct Derived2 : Base{
    constexpr int Get() const override {
        return 2;
    }
};

constexpr auto GetSum(){
    const Derived1 d1;
    const Derived2 d2;
    const Base* pb1 = &d1;
    const Base* pb2 = &d2;

    return pb1->Get() + pb2->Get();
}

constexpr         // error
int x = GetSum();   // OK if not in constexpr context

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

* [Bug c++/99495] constexpr virtual destructor is used before its definition
  2021-03-09 19:14 [Bug c++/99495] New: constexpr virtual destructor is used before its definition oleksandr.koval.dev at gmail dot com
@ 2021-04-24  2:38 ` pdimov at gmail dot com
  2021-08-17  5:57 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pdimov at gmail dot com @ 2021-04-24  2:38 UTC (permalink / raw)
  To: gcc-bugs

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

Peter Dimov <pdimov at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pdimov at gmail dot com

--- Comment #1 from Peter Dimov <pdimov at gmail dot com> ---
Simplified:

```
struct Base
{
    constexpr virtual ~Base() = default;
};

constexpr Base b;
```

https://godbolt.org/z/qGn1nx9ET

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

* [Bug c++/99495] constexpr virtual destructor is used before its definition
  2021-03-09 19:14 [Bug c++/99495] New: constexpr virtual destructor is used before its definition oleksandr.koval.dev at gmail dot com
  2021-04-24  2:38 ` [Bug c++/99495] " pdimov at gmail dot com
@ 2021-08-17  5:57 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-17  5:57 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 93413.

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

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

end of thread, other threads:[~2021-08-17  5:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-09 19:14 [Bug c++/99495] New: constexpr virtual destructor is used before its definition oleksandr.koval.dev at gmail dot com
2021-04-24  2:38 ` [Bug c++/99495] " pdimov at gmail dot com
2021-08-17  5:57 ` 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).