ashgti wrote:

I also added some unit tests for the new 'CapabilitiesEventBody' serialization 
logic. But I have a style question.

The existing `Capabilities` type doesn't initialize its fields, so if I use the 
aggregate I have to include all the fields. However, we could initialize the 
values and then the aggregate initializer is short, but that leads to my style 
questions.

```c++
// style 1, no initializers:
struct Capabilities {
  llvm::DenseSet<AdapterFeature> supportedFeatures;
  std::optional<std::vector<ExceptionBreakpointsFilter>> 
exceptionBreakpointFilters;
  std::optional<std::vector<std::string>> completionTriggerCharacters;
....
};
// all fields must be set or we get a warning on `-Wmissing-field-initializers`
Capabilities cap{
  /*supportedFeatures=*/{...},
  /*exceptionBreakpointFilters=*/std::nullopt,
  /*completionTriggerCharacters=*/std::nullopt
...
};


// style 2, = initial value:
struct Capabilities {
  llvm::DenseSet<AdapterFeature> supportedFeatures = {};
  std::optional<std::vector<ExceptionBreakpointsFilter>> 
exceptionBreakpointFilters = std::nullopt;
  std::optional<std::vector<std::string>> completionTriggerCharacters = 
std::nullopt;
....
};
Capabilities cap{/*supportedFeatures=*/{...}}; // no need to specify the 
nullopts.


// style 3, brace initializers:
struct Capabilities {
  llvm::DenseSet<AdapterFeature> supportedFeatures{};
  std::optional<std::vector<ExceptionBreakpointsFilter>> 
exceptionBreakpointFilters{};
  std::optional<std::vector<std::string>> completionTriggerCharacters{};
....
};
Capabilities cap{/*supportedFeatures=*/{...}}; // no need to specify the 
nullopts.
```


https://github.com/llvm/llvm-project/pull/142831
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to