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

v25.0 regression: C2370 compile error from map_field.h when compiling with cl.exe and /permissive- option #14602

Closed
yukawa opened this issue Nov 2, 2023 · 3 comments
Assignees
Labels

Comments

@yukawa
Copy link
Contributor

yukawa commented Nov 2, 2023

What version of protobuf and what language are you using?
Version: v25.0. Looks like a regression in 95d5723.
Language: C++

What operating system (Linux, Windows, ...) and version?
Windows 11 ver 22H2 (OS Build 22621.2428)

What runtime / compiler are you using (e.g., python version or gcc version)

  • Microsoft Visual Studio Community 2022 (64-bit) Version 17.7.0
    • Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32822 for x64
    • cmake version 3.26.4-msvc4

What did you do?
Steps to reproduce the behavior:

"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64_x86
git clone -b v25.0 https://github.com/protocolbuffers/protobuf.git --recursive
cd protobuf
cmake . -DCMAKE_CXX_STANDARD=20 -Dprotobuf_ABSL_PROVIDER=module
cmake --build . -j

What did you expect to see
Build succeeds.

What did you see instead?
Build fails with the following error.

printer.cc
C:\Users\builder\source\repos\protobuf\src\google/protobuf/map_field.h(682,66): error C2370: 'google::protobuf::internal::MapField<Derived,Key,T,kKeyFieldType_,kValueFieldType_>::kVTable': redefinition; different storage class (compiling source file C:\Users\builder\source\repos\protobuf\src\google\protobuf\struct.pb.cc) [C:\Users\builder\source\repos\protobuf\libprotobuf.vcxproj]
C:\Users\builder\source\repos\protobuf\src\google/protobuf/map_field.h(671,37): message : see declaration of 'google::protobuf::internal::MapField<Derived,Key,T,kKeyFieldType_,kValueFieldType_>::kVTable' (compiling source file C:\Users\builder\source\repos\protobuf\src\google\protobuf\struct.pb.cc) [C:\Users\builder\source\repos\protobuf\libprotobuf.vcxproj]
  strtod.cc

It's failing here.

static const MapFieldBase::VTable kVTable;
friend class google::protobuf::Arena;
friend class MapFieldBase;
friend class MapFieldStateTest; // For testing, it needs raw access to impl_
};
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType_,
WireFormatLite::FieldType kValueFieldType_>
constexpr MapFieldBase::VTable
MapField<Derived, Key, T, kKeyFieldType_, kValueFieldType_>::kVTable =
MapField::template MakeVTable<MapField>();

Anything else we should know about your project / environment

Seems that this is a known issue in cl.exe.

The tricky thing is that /permissive- is enabled by default when /std:c++20 is specified. While developers can still work around this by manually setting /permissive only when building protobuf, it'd be really nice if we can avoid this error in protobuf in the first place.

@yukawa yukawa added the untriaged auto added to all issues by default when created. label Nov 2, 2023
@yukawa yukawa changed the title C2370 compile error from map_field.h when compiling with cl.exe and /permissive- option v25.0 regression: C2370 compile error from map_field.h when compiling with cl.exe and /permissive- option Nov 2, 2023
@hlopko hlopko added c++ and removed untriaged auto added to all issues by default when created. labels Nov 2, 2023
copybara-service bot pushed a commit that referenced this issue Nov 2, 2023
Fixes #14602

PiperOrigin-RevId: 578835900
copybara-service bot pushed a commit that referenced this issue Nov 2, 2023
Fixes #14602

PiperOrigin-RevId: 578835900
copybara-service bot pushed a commit that referenced this issue Nov 2, 2023
Fixes #14602

PiperOrigin-RevId: 578835900
copybara-service bot pushed a commit that referenced this issue Nov 2, 2023
Fixes #14602

PiperOrigin-RevId: 578835900
Mizux added a commit to google/or-tools that referenced this issue Nov 10, 2023
@bebuch
Copy link

bebuch commented Nov 29, 2023

Same bug in 25.1

Can you please merge f78f9c5 into the 25.x line?

wangjiezhe added a commit to wangjiezhe/gentoo-local that referenced this issue Dec 23, 2023
@ericroy
Copy link

ericroy commented Jan 13, 2024

Still not fixed in 25.2
The key to reproducing is that you must compile as c++20 (CMAKE_CXX_STANDARD=20)

@versat
Copy link

versat commented Feb 7, 2024

Still not fixed in 25.2 The key to reproducing is that you must compile as c++20 (CMAKE_CXX_STANDARD=20)

Looks like we have to wait until 26.0 is released. I hope there will not be any issues again :(

hiroyuki-komatsu pushed a commit to google/mozc that referenced this issue Mar 16, 2024
This is a follow up commit to my previous commit [1] for #841, which
made protobuf.gyp compatible with Protobuf v25.0 to work around a
compile error [2].

Now that Mozc has switched to Protobuf v26.0 [3] (#871), this work
around is no longer necessary.

 [1]: 013e8aa
 [2]: protocolbuffers/protobuf#14602
 [3]: 0df12d0

#codehealth

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

Successfully merging a pull request may close this issue.

6 participants