Skip to content

[pigeon] C++ generator creates classes with uninitialized fields #104653

@stuartmorgan-g

Description

@stuartmorgan-g

Currently C++ data classes can have uninitialized primitive fields. For example, this Pigeon:

class Foo {
  Foo(this.bar);
  bool? bar;  // This should be just "bool" for this example, but see https://github.com/flutter/flutter/issues/104278
}

creates this C++ code:

// .h
class Foo {
 public:
  Foo();
  ...
 private:
  bool bar_; // This is incorrect for `bool?`, but would be right for `bool`.
}

// .cpp
Foo::Foo() {} // This leaves bar_ uninitialized

Once we fix bool? to map to std::optional<bool> the bool? will be fine since it has an initializer, but the bool case will still be wrong. We need to either only have public constructors that take arguments for all non-nullable POD fields, or have POD data be default-initialized (to a zero-like value) by the default constructor.

Related to #104278, but this is about problems when creating instances of data classes in C++ code (I ran into it in tests; would also apply to host->Dart calls). Also related to #104286

/cc @azchohfi FYI

Metadata

Metadata

Labels

P2Important issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.platform-windowsBuilding on or for Windows specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions