-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
flutter/packages
#3585Closed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specifically
Description
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
azchohfi
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specifically