Commit b553d38
committed
[RF] Fix ambiguity when calling RooDataHist constructor in PyROOT
The RooDataHist has two similar constructors:
```C++
RooDataHist(RooStringView name, RooStringView title, const RooArgSet& vars, const char* binningName);
RooDataHist(RooStringView name, RooStringView title, const RooArgList& vars, const RooCmdArg& arg1);
```
The problem: a `RooCmdArg` can be implicitly constructed from a `const
char*`. Therefore, if one doesn't explicitly choose one of the two
overloads by passing a RooArgSet or RooArgList as the third argument
explicitly, both overloads are succeeding in PyROOT. Unlike in C++,
the overload that doesn't require implicit conversion is not
prioritized.
Here is an example of where this goes wrong:
```Python
ROOT.RooDataHist(name, title, variables, "my_binning")
```
...causing...
```
[#0] ERROR:InputArguments -- RooDataHist::ctor() ERROR: unrecognized command: my_binning
```
...because the constructor with the RooCmdArg is used.
It was sheer luck that this problem didn't appear so far. It only
appeared after the the constructors were changed to use `RooStringView`,
probably because the order is which the overloads are tried is not well
defined.
The solution: make the implicit construction of `RooCmdArg` from just a
string impossible. This is done by requiring at least one non-default
payload parameter. This is not breaking any code, because constructing a
RooCmdArg without any payload doesn't make sense anyway.1 parent 51c8b8f commit b553d38
1 file changed
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | | - | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
| |||
0 commit comments