Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++23 support #17253

Merged
merged 1 commit into from
Dec 14, 2024
Merged

Add C++23 support #17253

merged 1 commit into from
Dec 14, 2024

Conversation

CHN-beta
Copy link
Contributor

This Pull request:

Changes or fixes:

C++23 support of ROOT (see https://root-forum.cern.ch/t/enable-c-23-in-root-6-34-00-rc1/62433).

Some changes are needed for code using std::unique_ptr. According to C++ standards, in the context that T is declared but not defined, std::unique_ptr<T> is constructible but not destructible, thus we need to move the definitions of some functions calling std::unique_ptr<T>::~unique_ptr from the header file into the source file. This rule is not new in C++ 23, but it causes compile failure when -std=c++23 is specified, so we must fix it to support C++ 23.

Checklist:

  • tested changes locally -- but I only tested these changes on 6.34.00-rc1, not on master. If test on master is mandatory, please tell me and I will do it tomorrow.
  • updated the docs (if necessary)

@ferdymercury ferdymercury changed the title Fix C++23 support Add C++23 support Dec 11, 2024
@dpiparo
Copy link
Member

dpiparo commented Dec 12, 2024

Thanks for these changes. I started the builds and tests on the master branch.

Copy link
Contributor

@osschar osschar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for graf3d/eve7 -- thank you!

Copy link
Member

@dpiparo dpiparo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this nice PR. I left two comments in the code, which will be easily addressed. Would you mind also proposing the changes in 1 single commit? Once this is merged, I will enable 23 for a few builds.

@@ -70,8 +70,7 @@ template <class T>
std::unique_ptr<T> compileForNormSet(T const &arg, RooArgSet const &normSet)
{
RooFit::Detail::CompileContext ctx{normSet};
std::unique_ptr<RooAbsArg> head = arg.compileForNormSet(normSet, ctx);
return std::unique_ptr<T>{static_cast<T *>(head.release())};
return std::unique_ptr<T>{static_cast<T *>(arg.compileForNormSet(normSet, ctx).release())};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please comment about the need of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let me explain the need of this change.

In the code without my patch, std::unque_ptr<RooAbsArg> head is constructed in the function, and it is needed to be destructed at the end of the function. However, RooAbsArg was still not defined, so it could not be destructed. In my test (gcc 13, with -std=c++23), this will cause a compile error.

So, generally speaking, we should move the function body to c++ source file. However, this is a function template, simply move the definition into source file will lead to failure in template implicit instantiation. Thus, I removed the definition of local variable head to avoid calling to its destrutor.

Of course, the return value of arg.compileForNormSet(normSet, ctx) is typed std::unqie_ptr and should also be destructed in this function, but this will not cause a compile error in my test. To my understand, this is because compiler did not know the type of the return value of arg.compileForNormSet before T is specified (i.e., before the function template is called and instantiated), so this statement will only be compiled when T is specified (i.e. when the function is actually called, where the template is implicitely instantiated). I am not sure this is a compiler specified behavior or in C++ standard.

roofit/histfactory/inc/RooStats/HistFactory/HistRef.h Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Dec 12, 2024

Test Results

    18 files      18 suites   4d 12h 56m 1s ⏱️
 2 665 tests  2 664 ✅ 0 💤 1 ❌
46 250 runs  46 249 ✅ 0 💤 1 ❌

For more details on these failures, see this check.

Results for commit 1d2acc9.

♻️ This comment has been updated with latest results.

@CHN-beta
Copy link
Contributor Author

Would you mind also proposing the changes in 1 single commit?

No problem.

@dpiparo
Copy link
Member

dpiparo commented Dec 13, 2024

Would you mind also proposing the changes in 1 single commit?

No problem.

Thank you.

@dpiparo dpiparo merged commit af97e5e into root-project:master Dec 14, 2024
18 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants