Skip to content

avoid "unknown pragma" warnings on MSVC - #8045

Merged
timosachsenberg merged 2 commits into
OpenMS:developfrom
cbielow:fix_im_tv
May 15, 2025
Merged

timosachsenberg merged 2 commits into
OpenMS:developfrom
cbielow:fix_im_tv

Conversation

@cbielow

@cbielow cbielow commented May 14, 2025 •

Copy link
Copy Markdown
Contributor

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 times

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

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.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • Refactor

    • Modernized several classes to use compiler-generated default equality operators and tuple-based comparisons for clarity and conciseness.
    • Updated internal data structures to use std::array for improved safety and maintainability.
    • Simplified comparator logic in metadata classes for more readable code.
  • Style

    • Improved code consistency by aligning iterator naming with standard conventions.
  • Chores

    • Adjusted compiler-specific warning suppressions to only apply when using Clang, ensuring broader compatibility.

@coderabbitai

coderabbitai Bot commented May 14, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This 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 DPosition to std::array, and applies conditional compilation for Clang-specific pragmas. Some comparator functions are also simplified using tuple comparisons. A conditional check in XML writing is clarified.

Changes

File(s) Change Summary
src/openms/include/OpenMS/ANALYSIS/ID/IDBoostGraph.h
src/openms/include/OpenMS/FORMAT/MzTab.h
Clang-specific pragma diagnostic push/pop and warning suppression are now wrapped in #ifdef __clang__ guards to restrict their application to Clang compilers only.
src/openms/include/OpenMS/CHEMISTRY/MASSDECOMPOSITION/IMS/IMSIsotopeDistribution.h
src/openms/include/OpenMS/KERNEL/ChromatogramPeak.h
src/openms/include/OpenMS/KERNEL/MobilityPeak1D.h
src/openms/include/OpenMS/KERNEL/Peak1D.h
src/openms/include/OpenMS/KERNEL/Peak2D.h
Equality operators are changed from manual member-wise comparison (with floating-point warning suppression) to compiler-generated defaulted operators (= default).
src/openms/include/OpenMS/KERNEL/MobilityPeak2D.h Equality operator implementation is refactored to use std::tie for concise tuple-based member comparison, removing explicit warning suppression.
src/openms/include/OpenMS/DATASTRUCTURES/DPosition.h Internal coordinate storage is refactored from C-style arrays to std::array, with updates to constructors, comparison, swap, clear, and iterator methods. Comparison operators now leverage std::array's default behavior.
src/openms/include/OpenMS/METADATA/ProteinHit.h The ScoreMore and ScoreLess comparator classes are refactored to use tuple-based lexicographical comparison, simplifying the logic and making the operator const.
src/openms/source/FORMAT/HANDLERS/MzDataHandler.cpp The conditional for writing <sampleDescription> is clarified to explicitly check for Sample::SAMPLENULL. Clang warning suppression pragmas are removed.

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
Loading

Possibly related PRs

  • OpenMS/OpenMS#7985: Refactors metadata handling in PeptideHit and PeptideIdentification, closely related to changes in comparator and equality operator logic in this PR.
  • OpenMS/OpenMS#7997: Refactors rank handling in PeptideHit, directly related to code-level changes in comparator logic and meta value usage.

Poem

A hop and a skip, some tuples in tow,
Arrays now in place where old pointers would go.
Equality’s easy, no loops to be found,
Pragmas for Clang only, the rest won’t confound.
With code modernized, the fields are in line—
This bunny approves of your C++ design!
🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/openms/include/OpenMS/KERNEL/MobilityPeak1D.h (1)

133-135: Same C++20 requirement as in Peak1D

The reasoning regarding = default for operator== applies here as well.
Refer to the comment in Peak1D.h and 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() and getAccession() methods.

src/openms/include/OpenMS/DATASTRUCTURES/DPosition.h (1)

346-365: Prefer using the STL iterators of std::array for clarity and zero-dim safety

Returning raw pointers works, but the intent is clearer – and safe for the hypothetical D == 0 case – 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 naming

While unrelated to the current PR changes, there's a minor inconsistency in the RTLess comparator where left.getRT() is compared with right.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

📥 Commits

Reviewing files that changed from the base of the PR and between fb3557d and 0bdc211.

📒 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 #endif directives 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 pop ensures 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 #endif directives 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 pop ensures 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() against Sample::SAMPLENULL instead 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:

  1. Improves code clarity via the lexicographical comparison
  2. Introduces template flexibility
  3. 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 = default for operator== 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

  1. switch the project to C++20, or
  2. 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_comparison etc.).

src/openms/include/OpenMS/KERNEL/Peak2D.h (1)

198-198: Good use of defaulted equality operator

Replacing 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 operator

This 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 operator

This 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.

Comment on lines 195 to 197
{
#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_);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
{
#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>

@cbielow
cbielow enabled auto-merge May 14, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants