-
Notifications
You must be signed in to change notification settings - Fork 278
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
Upgrade C++ standard to c++17 #2052
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2052 +/- ##
==========================================
- Coverage 61.48% 5.72% -55.77%
==========================================
Files 96 96
Lines 19192 18940 -252
Branches 9842 9840 -2
==========================================
- Hits 11801 1085 -10716
- Misses 5077 17667 +12590
+ Partials 2314 188 -2126
Continue to review full report at Codecov.
|
I need to also fix the compilation with clang + samples:
|
This pull request fixes 1 alert when merging 0a1e08c into 825c0c7 - view on LGTM.com fixed alerts:
|
This pull request fixes 7 alerts when merging 4871afe into 825c0c7 - view on LGTM.com fixed alerts:
|
@@ -32,7 +32,7 @@ option( EXIV2_ENABLE_WEBREADY "Build webready support into library" | |||
option( EXIV2_ENABLE_CURL "USE Libcurl for HttpIo (WEBREADY)" OFF ) | |||
option( EXIV2_ENABLE_BMFF "Build with BMFF support" ON ) | |||
|
|||
option( EXIV2_BUILD_SAMPLES "Build sample applications" ON ) | |||
option( EXIV2_BUILD_SAMPLES "Build sample applications" OFF ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to disable that because the workflow .github/workflows/cifuzz.yml
was failing to compile the project with clang14 (due to the issue with the Jzon class + C++17).
This pull request fixes 7 alerts when merging 7f1b7c7 into 825c0c7 - view on LGTM.com fixed alerts:
|
‘’’ Needs to be defined for clang. |
include/exiv2/jpgimage.hpp
Outdated
static const char* const bimId_; //!< %Photoshop IRB marker (deprecated) | ||
static const uint16_t iptc_; //!< %Photoshop IPTC marker | ||
static const uint16_t preview_; //!< %Photoshop preview marker | ||
inline static const char* const ps3Id_ = "Photoshop 3.0\0"; //!< %Photoshop marker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK inline here is redundant. static implies inline. This should also be constexpr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe even std::string_view. Although I assume that would break API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think static
implies inline
. The inline
specified for static variable members is something new in C++17:
https://en.cppreference.com/w/cpp/language/inline
I just did this change because the previous code was failing to compile with C++17.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's constexpr that implies inline.
what compile error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked it out. It was actually not a compiler error but linking one:
-- Build files have been written to: /media/linuxDev/programming/exiv2/buildRelease
[134/183] Linking CXX executable bin/key-test
FAILED: bin/key-test
: && ccache /usr/bin/c++ -O3 -DNDEBUG -fstack-protector-strong samples/CMakeFiles/key-test.dir/key-test.cpp.o -o bin/key-test -Wl,-rpath,/media/linuxDev/programming/exiv2/buildRelease/lib lib/libexiv2.so.1.0.0.9 /home/luis/.conan/data/zlib/1.2.11/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libz.a && :
/usr/bin/ld: lib/libexiv2.so.1.0.0.9: undefined reference to `Exiv2::Photoshop::irbId_'
I think the problem is that in the header file it was declared as:
static const std::array<const char*, 4> irbId_;
While in the cpp file:
constexpr std::array<const char*, 4> Photoshop::irbId_
I could also declare it as constexpr
in the header file as you suggested so that we do not need to add the inline
specifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that error has to do with Windows and dllexport. defining them in the header is the correct solution.
Small nitpick: static constexpr vs. constexpr static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually got the error on Ubuntu 20.4 with Gcc-10 😅 . I'll change the order to static constexpr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized. C++17 supports CTAD. You can safely ommit the template parameters.
samples/Jzon.cpp
Outdated
@@ -25,6 +25,10 @@ THE SOFTWARE. | |||
#define JzonAPI __declspec(dllexport) | |||
#endif | |||
|
|||
#ifdef WIN32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be _MSC_VER or something. Not relevant for mingw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking of this it would probably be a good idea to set up an msys CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI does build MinGW/msys2. We don't have that in the nightly GHA build. Would you like to change/fix that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually have that MSYS2 build which is triggered on PRs:
https://github.com/Exiv2/exiv2/actions/runs/1670765792
I think it is enough to have it there and not in the nightly builds.
Now that I think about it, on Windows + MSYS2, it is ending up using MinGW (with gcc-11). The problem with the Jzon
class is only reproducible with VisualStudio and very recent versions of clang.
I added this and enable back the SAMPLES=ON , so that the CIFuzz job could run with the samples, but the problem persist: https://github.com/Exiv2/exiv2/runs/4746935159?check_suite_focus=true It looks like that definition for clang does not generate the expected behavior. |
This pull request fixes 1 alert when merging 6b73b7e into 825c0c7 - view on LGTM.com fixed alerts:
|
This pull request fixes 7 alerts when merging d39767c into 825c0c7 - view on LGTM.com fixed alerts:
|
maybe it needs to be set earlier. who knows. edit: maybe set _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES in Jzon.h |
I would not like to spend more time on that Jzon class at the moment. Yesterday I triggered a discussion about how useful that |
This pull request fixes 7 alerts when merging 64da72a into 825c0c7 - view on LGTM.com fixed alerts:
|
@piponazo If the JSON code is causing you trouble with MSVC, then don't build it on that platform. It'll be something like this in samples/CMakeLists.txt
I'm sure CMake knows the version of Visual Studio, so you can probably continue to build it on 2017 and 2019. |
I just needed to add a compiler definition in the Jzon.cpp file to surpass that error. I did not want to spend much time in that class since it is part of a sample app and not part of the exiv2 library. Right now the work in this branch is done and we could merge it as it is (when somebody approves the PR). |
I'm happy to approve that, although I don't know C++17. However @neheb has commented, so I believe the code is good. |
Let's adopt the convention that the person how opens a PR almost merges it. |
As discussed in #2051, we thought it would be a good idea to start using C++17 so that we can use some new available features to simplify our codebase.