plumed / plumed2

Development version of plumed 2
https://www.plumed.org
GNU Lesser General Public License v3.0
323 stars 269 forks source link

Removed old-style-cast from Plumed.h #1090

Open Iximiel opened 6 days ago

Iximiel commented 6 days ago
Description

I removed the old-style casts in Plumed.h.

Now when Plumed.h is in "c++ mode" will use static_cast or reintrpet_cast

I used -Werror=old-style-cast to find the casts and i changed to static when gcc suggested to change to static and reintepret otherwise or when no suggestion were made.

I am not 100% sure to have changed every casts, but at least the ones that affects the gromacs compilation are done plus some more found with searching \(.*?\)\w.

Target release

I would like my code to appear in release 2.10

Type of contribution
Copyright
Tests
GiovanniBussi commented 6 days ago

For clarity, I would:

Indeed, I see you only use it in regions of the code that are C++ only, so no reason to use this macro

Thanks!

Iximiel commented 6 days ago

Indeed, I see you only use it in regions of the code that are C++ only, so no reason to use this macro

I changed it in the std::filesystem part but some of them are in the f2c, c2f, c2v and v2c functions that are wrapped by __PLUMED_WRAPPER_C_BEGIN/END, are also these only c++?

Then I run astyle, and should be ready

GiovanniBussi commented 6 days ago

You are right, those are also for C. So we can either keep it as is or maybe you can put explicit reinterpret_cast in the filesystem part, just because it's clearer...

Iximiel commented 6 days ago

You are right, those are also for C. So we can either keep it as is or maybe you can put explicit reinterpret_cast in the filesystem part, just because it's clearer...

i changed CAST to REINTERPRET_CAST, so it is clearer, and in the c++ parts I wrote it explicitly

Iximiel commented 5 days ago

The changes should not be accepted, using clang12 for compiling raises a warning about some of the cast to be undefined behaviour. I think I should address this before considering the work done

Iximiel commented 5 days ago

I think I solved the issue, I do not get anymore the UB warnings. And the solution should be compatible with C++98

GiovanniBussi commented 5 days ago

@Iximiel I think I can merge this, but you should first make it "not draft" I think