Skip to content

[MSVC] Compile error protobuf\src\google\protobuf\json\internal\unparser.cc with /std:c++20 or later #21310

Open
@NEIL-smtg

Description

@NEIL-smtg

What version of protobuf and what language are you using?
Version: main
Language: C++

What operating system (Linux, Windows, ...) and version?
Windows 11

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

What did you do?
Steps to reproduce the behavior:

  1. open x64 native tools command prompt for VS2022
  2. git clone https://github.com/protocolbuffers/protobuf.git
  3. set _CL_=/std:c++latest /Zc:__cplusplus
  4. mkdir protobuf\build_amd64 & cd protobuf\build_amd64
  5. cmake -G Ninja -Dprotobuf_BUILD_TESTS=ON -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_EXAMPLES=ON ..
  6. ninja -v

What did you expect to see
Build successful

What did you see instead?

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\include\xsmf_control.h(49): error C2139: 'google::protobuf::json_internal::UntypedMessage': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_constructible'
C:\gitP\google\protobuf\src\google/protobuf/json/internal/untyped_message.h(148): note: see declaration of 'google::protobuf::json_internal::UntypedMessage'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\include\xsmf_control.h(49): note: the template instantiation context (the oldest one first) is
C:\gitP\google\protobuf\src\google/protobuf/json/internal/untyped_message.h(233): note: see reference to class template instantiation 'absl::lts_20250127::flat_hash_map<int32_t,google::protobuf::json_internal::UntypedMessage::Value,absl::lts_20250127::hash_internal::Hash<T>,std::equal_to<T>,std::allocator<std::pair<const K,V>>>' being compiled
        with
        [
            T=int32_t,
            K=int32_t,
            V=google::protobuf::json_internal::UntypedMessage::Value
        ]
C:\gitP\google\protobuf\build_amd64\_deps\absl-src\absl/container/flat_hash_map.h(129): note: see reference to class template instantiation 'absl::lts_20250127::container_internal::raw_hash_map<absl::lts_20250127::container_internal::FlatHashMapPolicy<K,V>,Hash,Eq,Allocator>' being compiled
        with
        [
            K=int32_t,
            V=google::protobuf::json_internal::UntypedMessage::Value,
            Hash=absl::lts_20250127::hash_internal::Hash<int32_t>,
            Eq=std::equal_to<int32_t>,
            Allocator=std::allocator<std::pair<const int32_t,google::protobuf::json_internal::UntypedMessage::Value>>
        ]
C:\gitP\google\protobuf\build_amd64\_deps\absl-src\absl/container/internal/raw_hash_map.h(33): note: see reference to class template instantiation 'absl::lts_20250127::container_internal::raw_hash_set<Policy,Hash,Eq,Alloc>' being compiled
        with
        [
            Policy=absl::lts_20250127::container_internal::FlatHashMapPolicy<int32_t,google::protobuf::json_internal::UntypedMessage::Value>,
            Hash=absl::lts_20250127::hash_internal::Hash<int32_t>,
            Eq=std::equal_to<int32_t>,
            Alloc=std::allocator<std::pair<const int32_t,google::protobuf::json_internal::UntypedMessage::Value>>
        ]

Full build log: protobuf_build.txt

Note: The issue persists when building with /std:c++20 as well. Feel free to close this issue if you guys are not supporting /std:c++20 or later.

Anything else we should know about your project / environment
N/A

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions