[RF] Don't allow passing temporaries to RooArgList/Set constructors#8065
[RF] Don't allow passing temporaries to RooArgList/Set constructors#8065guitargeek merged 1 commit intoroot-project:masterfrom
Conversation
|
Starting build on |
|
Starting build on |
|
Starting build on |
|
Build failed on ROOT-debian10-i386/cxx14. Failing tests: |
|
Starting build on |
|
Build failed on ROOT-debian10-i386/cxx14. Errors:
|
|
Starting build on |
|
Build failed on ROOT-debian10-i386/cxx14. Errors:
|
|
Build failed on ROOT-ubuntu16/nortcxxmod. Failing tests: |
roofit/roofitcore/inc/RooArgList.h
Outdated
| /// RooAbsArg as r-value reference is not allowed. | ||
| template<typename... Arg_t> | ||
| RooArgList(RooAbsArg && arg, Arg_t &&... argsOrName) | ||
| : RooArgList{arg, std::move(arg), std::forward<Arg_t>(argsOrName)...} {} |
There was a problem hiding this comment.
Really std::move(arg), not forward?
There was a problem hiding this comment.
I would stay std::move, because here the RooAbsArg && arg is not a universal reference but an r-value reference.
I I think the more general std::forward is intended to forward universal references correctly, but here I explicitly create a new r-value reference from arg, which is what move does. Of course they both work, if you want I can change :)
There was a problem hiding this comment.
(rebasing and solving conflicts in this PR at the moment)
There was a problem hiding this comment.
Oh, so you want temporaries all the way in the arguments? That might work indeed.
The two classes inheriting from RooAbsCollection, namely RooArgList and RooArgSet are by default non-owning collections. This means they should not be initialized with temporary objects, otherwise they contain invalid pointers right after construction. To avoid that this can ever happen, the universal reference mechanism is used to statically check for temporaries, such that your code doesn't even compile if you try to construct a RooArgList or RooArgSet from temporaries.
|
Starting build on |
|
Build failed on ROOT-debian10-i386/cxx14. Errors:
|
|
Build failed on ROOT-ubuntu16/nortcxxmod. Failing tests: |
lmoneta
left a comment
There was a problem hiding this comment.
Very nice addition to avoid the problem of temporaries.
I think the PR is good to be merged.
The two classes inheriting from RooAbsCollection, namely RooArgList and
RooArgSet are by default non-owning collections. This means they should
not be initialized with temporary objects, otherwise they contain
invalid pointers right after construction.
To avoid that this can ever happen, the universal reference mechanism is
used to statically check for temporaries, such that your code doesn't
even compile if you try to construct a RooArgList or RooArgSet from
temporaries.
This fixes #8052.
Some C++ code to validate that the
static_assertworks: