Repository navigation
avoid "unknown pragma" warnings on MSVC - #8045
Conversation
WalkthroughThis update modernizes and refactors several OpenMS header files and one source file. It replaces manual implementations of equality operators with defaulted or tuple-based comparisons, switches internal storage in Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant OpenMS_Class
participant Compiler
User->>OpenMS_Class: Compare two objects (==)
OpenMS_Class->>Compiler: Use defaulted or tuple-based operator==
Compiler-->>OpenMS_Class: Generate member-wise comparison
OpenMS_Class-->>User: Return comparison result
Possibly related PRs
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/openms/include/OpenMS/KERNEL/MobilityPeak1D.h (1)
133-135: Same C++20 requirement as inPeak1DThe reasoning regarding
= defaultforoperator==applies here as well.
Refer to the comment inPeak1D.hand ensure the compiler standard matches.
🧹 Nitpick comments (3)
src/openms/include/OpenMS/METADATA/ProteinHit.h (1)
66-82: Consider adding type constraints in a future update.While not critical for this PR, a future improvement could add type constraints to the templates using C++20 concepts or SFINAE to ensure the template arguments provide the required
getScore()andgetAccession()methods.src/openms/include/OpenMS/DATASTRUCTURES/DPosition.h (1)
346-365: Prefer using the STL iterators ofstd::arrayfor clarity and zero-dim safetyReturning raw pointers works, but the intent is clearer – and safe for the hypothetical
D == 0case – when delegated to the container’s own iterators:-const_iterator begin() const { return &coordinate_[0]; } -const_iterator end() const { return &coordinate_[0] + D; } -iterator begin() { return &coordinate_[0]; } -iterator end() { return &coordinate_[0] + D; } +const_iterator begin() const { return coordinate_.begin(); } +const_iterator end() const { return coordinate_.end(); } +iterator begin() { return coordinate_.begin(); } +iterator end() { return coordinate_.end(); }This is a minor readability refactor; functionality is unaffected.
src/openms/include/OpenMS/KERNEL/ChromatogramPeak.h (1)
187-189: Minor inconsistency in method namingWhile unrelated to the current PR changes, there's a minor inconsistency in the RTLess comparator where
left.getRT()is compared withright.getPos(). Although these methods are functionally equivalent (aliases), it would be more consistent to use the same method for both sides of the comparison.inline bool operator()(const ChromatogramPeak & left, const ChromatogramPeak & right) const { - return left.getRT() < right.getPos(); + return left.getRT() < right.getRT(); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
src/openms/include/OpenMS/ANALYSIS/ID/IDBoostGraph.h(2 hunks)src/openms/include/OpenMS/CHEMISTRY/MASSDECOMPOSITION/IMS/IMSIsotopeDistribution.h(1 hunks)src/openms/include/OpenMS/DATASTRUCTURES/DPosition.h(4 hunks)src/openms/include/OpenMS/FORMAT/MzTab.h(2 hunks)src/openms/include/OpenMS/KERNEL/ChromatogramPeak.h(1 hunks)src/openms/include/OpenMS/KERNEL/MobilityPeak1D.h(1 hunks)src/openms/include/OpenMS/KERNEL/MobilityPeak2D.h(1 hunks)src/openms/include/OpenMS/KERNEL/Peak1D.h(1 hunks)src/openms/include/OpenMS/KERNEL/Peak2D.h(1 hunks)src/openms/include/OpenMS/METADATA/ProteinHit.h(1 hunks)src/openms/source/FORMAT/HANDLERS/MzDataHandler.cpp(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/openms/include/OpenMS/KERNEL/MobilityPeak2D.h (2)
src/openms/include/OpenMS/KERNEL/ChromatogramPeak.h (5)
rhs(133-141)rhs(133-133)rhs(144-144)rhs(147-150)rhs(147-147)src/openms/include/OpenMS/KERNEL/MobilityPeak1D.h (4)
rhs(56-56)rhs(134-134)rhs(137-140)rhs(137-137)
src/openms/include/OpenMS/KERNEL/Peak2D.h (2)
src/openms/include/OpenMS/KERNEL/ChromatogramPeak.h (5)
rhs(133-141)rhs(133-133)rhs(144-144)rhs(147-150)rhs(147-147)src/openms/include/OpenMS/KERNEL/MobilityPeak2D.h (5)
rhs(120-120)rhs(194-197)rhs(194-194)rhs(200-203)rhs(200-200)
src/openms/include/OpenMS/KERNEL/ChromatogramPeak.h (3)
src/openms/include/OpenMS/KERNEL/MobilityPeak1D.h (4)
rhs(56-56)rhs(134-134)rhs(137-140)rhs(137-137)src/openms/include/OpenMS/KERNEL/MobilityPeak2D.h (5)
rhs(120-120)rhs(194-197)rhs(194-194)rhs(200-203)rhs(200-200)src/openms/include/OpenMS/KERNEL/Peak1D.h (4)
rhs(60-60)rhs(131-131)rhs(134-137)rhs(134-134)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
🔇 Additional comments (12)
src/openms/include/OpenMS/FORMAT/MzTab.h (2)
21-24: Good approach for conditionally applying Clang-specific diagnostics.The addition of
#ifdef __clang__and#endifdirectives around Clang-specific pragmas prevents MSVC from encountering "unknown pragma" warnings (C4068) while still maintaining the diagnostic control for Clang compilers.
879-881: Correctly guards the closing pragma directive.The matching
#ifdef __clang__enclosure around the closing#pragma clang diagnostic popensures consistent compilation across different compilers.src/openms/include/OpenMS/ANALYSIS/ID/IDBoostGraph.h (2)
62-65: Good approach for conditionally applying Clang-specific diagnostics.The addition of
#ifdef __clang__and#endifdirectives around Clang-specific pragmas prevents MSVC from encountering "unknown pragma" warnings (C4068) when dealing with BOOST_STRONG_TYPEDEF's extra semicolons.
87-89: Correctly guards the closing pragma directive.The matching
#ifdef __clang__enclosure around the closing#pragma clang diagnostic popensures consistent compilation across different compilers.src/openms/source/FORMAT/HANDLERS/MzDataHandler.cpp (1)
594-594: Improved condition check with explicit comparison.The modified condition now explicitly compares
sm.getState()againstSample::SAMPLENULLinstead of relying on implicit boolean conversion. This makes the code more readable and prevents potential compiler warnings about implicit conversions.src/openms/include/OpenMS/METADATA/ProteinHit.h (2)
66-70: Well-executed refactoring of the ScoreMore comparator.The changes effectively replace what was likely explicit comparison code (possibly with compiler-specific pragmas) with a clean, tuple-based approach. This modification:
- Improves code clarity via the lexicographical comparison
- Introduces template flexibility
- Adds proper const-correctness to the operator
Most importantly, it succeeds in addressing the PR objective of avoiding unknown pragma warnings on MSVC by eliminating compiler-specific directives.
79-81: Good consistency in the ScoreLess implementation.The changes mirror those made to ScoreMore, maintaining consistency in the codebase. The tuple-based comparison elegantly handles the primary score comparison and the secondary accession-based tiebreaker in a single expression.
src/openms/include/OpenMS/KERNEL/Peak1D.h (1)
130-132: Check language standard – explicit= defaultforoperator==requires C++20
operator==is not a special member function, therefore explicitly defaulting it is only permitted starting with C++20.
If the OpenMS tool-chain is still compiled with-std=c++17(the current default for many CI jobs and MSVC 19.3x), this will fail to compile.Please verify the currently enforced standard and, if necessary, either
- switch the project to C++20, or
- fall back to the “classic” hand-written implementation (
return intensity_ == rhs.intensity_ && position_ == rhs.position_;).src/openms/include/OpenMS/DATASTRUCTURES/DPosition.h (1)
165-170: Non-special operators defaulted – again needs C++20
operator==/operator!=are explicitly defaulted.
Double-check that the build system enables C++20; otherwise these declarations must be replaced by hand-written definitions (or guarded by#if __cpp_impl_three_way_comparisonetc.).src/openms/include/OpenMS/KERNEL/Peak2D.h (1)
198-198: Good use of defaulted equality operatorReplacing the manually implemented equality operator with a defaulted one is an excellent solution to eliminate the Clang-specific pragmas that were causing "unknown pragma" warnings in MSVC. This approach is cleaner, more maintainable, and leverages modern C++ features while maintaining the same behavior.
src/openms/include/OpenMS/CHEMISTRY/MASSDECOMPOSITION/IMS/IMSIsotopeDistribution.h (1)
81-81: Consistent use of defaulted equality operatorThis change follows the same pattern as seen in other peak-related classes, defaulting the equality operator instead of using a manual implementation with floating-point comparison pragmas. This creates a more consistent codebase while eliminating the MSVC "unknown pragma" warnings.
src/openms/include/OpenMS/KERNEL/ChromatogramPeak.h (1)
144-144: Good modernization using defaulted equality operatorThis change correctly replaces a manually implemented equality operator with a defaulted one, consistent with the changes in other peak-related classes. This eliminates the MSVC "unknown pragma" warnings while maintaining the same behavior.
| { | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wfloat-equal" | ||
| return intensity_ == rhs.intensity_ && position_ == rhs.position_; | ||
| #pragma clang diagnostic pop | ||
| return std::tie(intensity_, position_) == std::tie(rhs.intensity_, rhs.position_); | ||
| } |
There was a problem hiding this comment.
Missing <tuple> include – std::tie is undefined
std::tie lives in <tuple>, not <functional>.
Under strict headers you will receive an “identifier ‘tie’ is undefined” error.
#include <functional>
+#include <tuple>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| { | |
| #pragma clang diagnostic push | |
| #pragma clang diagnostic ignored "-Wfloat-equal" | |
| return intensity_ == rhs.intensity_ && position_ == rhs.position_; | |
| #pragma clang diagnostic pop | |
| return std::tie(intensity_, position_) == std::tie(rhs.intensity_, rhs.position_); | |
| } | |
| #include <functional> | |
| #include <tuple> |
Description
rewrite to avoid
#pragma clang ..warnings on MSVC (https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4068?view=msvc-170), which occur hundreds of timesChecklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
Refactor
std::arrayfor improved safety and maintainability.Style
Chores