From 7f257e9e019a1a4c9f650f60af2d389d45b1ef23 Mon Sep 17 00:00:00 2001 From: Andreas Fertig Date: Sun, 29 Sep 2019 09:23:53 +0200 Subject: [PATCH] Fixed #236: Add missing virtual specifier for virtual inheritance. --- CodeGenerator.cpp | 5 ++++- tests/Issue236.cpp | 2 ++ tests/Issue236.expect | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/Issue236.cpp create mode 100644 tests/Issue236.expect diff --git a/CodeGenerator.cpp b/CodeGenerator.cpp index 1b7ddd2b..ee173105 100644 --- a/CodeGenerator.cpp +++ b/CodeGenerator.cpp @@ -2370,7 +2370,10 @@ void CodeGenerator::InsertArg(const CXXRecordDecl* stmt) mOutputFormatHelper.Append(" : "); ForEachArg(stmt->bases(), [&](const auto& base) { - mOutputFormatHelper.Append(AccessToString(base.getAccessSpecifier()), " ", GetName(base.getType())); + const std::string virtualKw{base.isVirtual() ? kwVirtualSpace : ""}; + + mOutputFormatHelper.Append( + AccessToString(base.getAccessSpecifier()), " ", virtualKw, GetName(base.getType())); }); } diff --git a/tests/Issue236.cpp b/tests/Issue236.cpp new file mode 100644 index 00000000..9252eda6 --- /dev/null +++ b/tests/Issue236.cpp @@ -0,0 +1,2 @@ +struct S {}; +class T : virtual S {}; diff --git a/tests/Issue236.expect b/tests/Issue236.expect new file mode 100644 index 00000000..3d01f3c2 --- /dev/null +++ b/tests/Issue236.expect @@ -0,0 +1,17 @@ +struct S +{ + // inline constexpr S & operator=(const S &) = default; + // inline constexpr S & operator=(S &&) = default; + // inline ~S() = default; +}; + + +class T : private virtual S +{ + public: + // inline T & operator=(const T &) = default; + // inline T & operator=(T &&) = default; + // inline ~T() = default; +}; + +