google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.73k stars 10.14k forks source link

[Bug]: error C2059: syntax error: 'static_cast' #4606

Closed Ekamjeet closed 2 weeks ago

Ekamjeet commented 2 months ago

Describe the issue

TestQualysAgent.cpp
1>    C:\data\qagent\Source\Agent\SupportLibs\GoogleTest\GoogleTest\googletest\include\gtest\gtest-matchers.h(412,14): error C2059: syntax error: 'static_cast'
1>    (compiling source file '/TestQualysAgent.cpp')

I'm getting above error while building the gtest (1.14.0) in visual studio 2022 (Platform Toolset - Visual Studio 2015 - Windows XP (v140_xp))

template <typename M, bool = MatcherBase::IsInlined<M>()> struct ValuePolicy { static const M& Get(const MatcherBase& m) { // When inlined along with Init, need to be explicit to avoid violating // strict aliasing rules. const M* ptr = static_cast<const M*>(static_cast<const void*>(&m.buffer_)); return *ptr; } static void Init(MatcherBase& m, M impl) { ::**new (static_cast<void*>(&m.buffer_)) M(impl);** //// Getting error on this line of code. } static constexpr auto shared_destroy = nullptr; };

Steps to reproduce the problem

While building to consume the gmock with our visual studio project.

What version of GoogleTest are you using?

1.14.0

What operating system and version are you using?

Edition Windows 11 Enterprise Version 23H2 Installed on ‎2/‎8/‎2024 OS build 22631.3880 Experience Windows Feature Experience Pack 1000.22700.1020.0

What compiler and version are you using?

Visual studio 2022 (Platform Toolset - Visual Studio 2015 - Windows XP (v140_xp))

What build system are you using?

MSVC

Additional context

No response

Ekamjeet commented 1 month ago

Any update on this!

Ekamjeet commented 1 month ago

Can you please help us resolving this issue?

gvatsal60 commented 1 month ago

@Ekamjeet Could you please share the error line of code from TestQualysAgent.cpp ?