public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98206] New: UBSan: Casting from multiple inheritance base to derived class triggers undefined behavior sanitizer
@ 2020-12-08 19:30 rbock at eudoxos dot de
  2020-12-08 19:40 ` [Bug c++/98206] " rbock at eudoxos dot de
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: rbock at eudoxos dot de @ 2020-12-08 19:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98206
           Summary: UBSan: Casting from multiple inheritance base to
                    derived class triggers undefined behavior sanitizer
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rbock at eudoxos dot de
  Target Milestone: ---

The following code incorrectly triggers undefined behavior sanitizer:

// -------------------------------------
#include <iostream>
#include <string_view>

template<typename Derived>
struct Base1
{
    char c1;
};

template<typename Derived>
struct Base2
{
    char c2;
    auto& get2() const
    {
        return static_cast<const Derived&>(*this);
    }
};

struct X : public Base1<X>, public Base2<X>
{
    X(std::string_view d) : data{d} {}

    std::string_view data;
};


int main()
{
    auto x = X{"cheesecake"};

    std::cout << x.get2().data << std::endl;
}
// -------------------------------------


See also discussion here:
https://stackoverflow.com/a/65178320/2173029

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

end of thread, other threads:[~2021-01-01 12:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 19:30 [Bug c++/98206] New: UBSan: Casting from multiple inheritance base to derived class triggers undefined behavior sanitizer rbock at eudoxos dot de
2020-12-08 19:40 ` [Bug c++/98206] " rbock at eudoxos dot de
2020-12-08 20:51 ` [Bug sanitizer/98206] " marxin at gcc dot gnu.org
2020-12-29 14:10 ` jakub at gcc dot gnu.org
2020-12-29 14:44 ` jakub at gcc dot gnu.org
2020-12-31  9:21 ` cvs-commit at gcc dot gnu.org
2021-01-01 12:13 ` rbock at eudoxos dot de

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