Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IUTEST_PEEP_GETに多重継承を行ったクラスを渡すと,期待される戻り値が得られない. #706

Open
HubMS opened this issue Nov 7, 2024 · 1 comment
Labels

Comments

@HubMS
Copy link

HubMS commented Nov 7, 2024

Describe the bug
多重継承を行ったクラスのprivateメンバ変数をIUTEST_PEEP_GETで取得すると,
戻り値が期待した値でない.
多重継承によるメモリレイアウトの影響が考えられる。

To Reproduce

  1. Additional contextに記載したmain関数を実行する.
  2. IUTEST(ClassAB, getPrivateValue)のテスト結果を参照する.

Expected behavior
IUTEST(ClassAB, getPrivateValue)において,Actual: 1となる.
privateValueはClassABのプライベートメンバであり、初期化時に1が設定されているため.

Screenshots
なし

Environment (please complete the following information):

  • OS: Windows 10 Pro 22H2
  • Compiler: MSVC
  • Version: 19.29.30156
  • Options: /JMC /permissive- /ifcOutput "Debug" /GS /analyze- /W3 /Zc:wchar_t /I"D:\WorkSpace\iutest_bug\iutest\include" /I"D:\WorkSpace\iutest_bug" /ZI /Gm- /Od /sdl /Fd"Debug\vc142.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /FC /Fa"Debug" /EHsc /nologo /Fo"Debug" /Fp"Debug\iutest_bug.pch" /diagnostics:column

Additional context
bugが発生するコード.

#include <iutest.hpp>

class IClassA
{
public:
    virtual void funcA() = 0;
};

class IClassB
{
public:
    virtual void funcB() = 0;
};

class ClassAB : public IClassA, public IClassB
{
private:
    int privateValue = 1;

public:
    void funcA() override {}
    void funcB() override {}
};

IUTEST_MAKE_PEEP(int ClassAB::*, ClassAB, privateValue);
IUTEST(ClassAB, getPrivateValue)
{
    ClassAB classAB;

    int actual = IUTEST_PEEP_GET(classAB, ClassAB, privateValue);
    IUTEST_EXPECT_EQ(1, actual);
}

class ClassA : public IClassA
{
private:
    int privateValue = 1;

public:
    void funcA() override {}
};

IUTEST_MAKE_PEEP(int ClassA::*, ClassA, privateValue);
IUTEST(ClassA, getPrivateValue)
{
    ClassA classA;

    int actual = IUTEST_PEEP_GET(classA, ClassA, privateValue);
    IUTEST_EXPECT_EQ(1, actual);
}

int main(int argc, char** argv)
{
    IUTEST_INIT(&argc, argv);
    return IUTEST_RUN_ALL_TESTS();
}

テスト結果.

[----------] 1 tests from ClassAB
[ RUN      ] ClassAB.getPrivateValue
iutest_bug.cpp(31): error: Value of actual
  Actual: 10609944
Expected: 1
[  FAILED  ] ClassAB.getPrivateValue (6ms)
[----------] 1 tests from ClassAB(9ms total)

[----------] 1 tests from ClassA
[ RUN      ] ClassA.getPrivateValue
[       OK ] ClassA.getPrivateValue (0ms)
[----------] 1 tests from ClassA(3ms total)

@HubMS HubMS added the bug label Nov 7, 2024
Copy link

github-actions bot commented Nov 7, 2024

Hey, thanks for contributing to this by raising an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant