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

Compilation error using Conformance mode in VS2022 #339

Open
noujaimc opened this issue Jun 4, 2024 · 2 comments
Open

Compilation error using Conformance mode in VS2022 #339

noujaimc opened this issue Jun 4, 2024 · 2 comments
Labels

Comments

@noujaimc
Copy link

noujaimc commented Jun 4, 2024

Hello,

during the upgrade of my project from Visual Studio 2019 to Visual Studio 2022, I encountered a compilation error related to the FakeIt library. Specifically, I’m using the single_header/mstest/fakeit.hpp header. When I enable conformance mode in VS2022, the following error occurs

C2440	'return': cannot convert from 'fakeit::MockingContext<void,const uint8_t [],int32_t,int32_t>' to 'fakeit::MockingContext<void,const uint8_t *,int32_t,int32_t>'		

Here is the code :

#include "pch.h"
#include "CppUnitTest.h"
#include "fakeit.hpp"

using namespace fakeit;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest
{
  class IClass
  {
     public:
       virtual void TestMethod(const uint8_t buffer[], int32_t offset, int32_t count) = 0;
       virtual ~IClass() = default;
   };
  
  TEST_CLASS(UnitTest)
  {
     public:
       TEST_METHOD(TestMethod1)
        {
	   Mock<IClass> mock;
           Fake(Method(mock, TestMethod));
        }
  };
}

fakeit

@malcolmdavey
Copy link
Contributor

Don't know a fix for fakeit, but it's unusual to have an array parameter in C++. I've used VS up to 2022, but never done that.

If using an array, it's better to actually have it as a reference with an actual size.
Also C++ allows reading the array size when templating const uint8_t (buffer&)[n], but then this may not suit a virtual method.

Not sure if changing this helps.

I guess the question is - why not otherwise have a pointer? Is it just trying to avoid a nullptr case?

@noujaimc
Copy link
Author

noujaimc commented Jun 5, 2024

I am aware that it's unusual to have an array parameter in C++, but I cannot simply change the signature of my code base for multiple reasons. I was able to compile every library I used in VS2022 except for this one. The code was compiling before in VS2019 with the conformance mode enabled.

@FranckRJ FranckRJ added the bug label Jun 6, 2024
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

3 participants