MSVC C6387 Warning · Issue #7108 · Protocolbuffers/protobuf · GitHub

Skip to content Dismiss alert {{ message }} / protobuf Public
  • Notifications You must be signed in to change notification settings
  • Fork 16k
  • Star 70k
  • Code
  • Issues 167
  • Pull requests 70
  • Actions
  • Projects
  • Wiki
  • Security

    Uh oh!

    There was an error while loading. Please reload this page.

  • Insights
Additional navigation options MSVC C6387 warning #7108New issueNew issueClosedClosedMSVC C6387 warning#7108Labelsc++cleanupplatform relatedAny issue releated to specific platform or OSprotocwindows@linquize

Description

@linquizelinquizeopened on Jan 20, 2020

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

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

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

What did you do? Steps to reproduce the behavior:

  1. create a proto3 message with a string field called String1
  2. use protoc to compile to C++
  3. compile the generated source using MSVC

What did you expect to see No C6387 warning

What did you see instead? C6387 warning 'value' could be '0': this does not adhere to the specification for the function 'std::basic_string<char,std::char_traits,std::allocator >::{ctor}'

The generated source is

inline void Proto1::set_string1(const char* value) { GOOGLE_DCHECK(value != nullptr); string1_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:Proto1.String1) }

It seems MSVC does not understand GOOGLE_DCHECK(value != nullptr);

If use ::std::string(value ? value : ""), the warning goes away.

Metadata

Metadata

Assignees

No one assigned

Labels

c++cleanupplatform relatedAny issue releated to specific platform or OSprotocwindows

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You can’t perform that action at this time.

Từ khóa » C C6387