FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(IWYU): force std:: or <> for max, min, copy by aaronliu0130 · Pull Request #411 · cpplint/cpplint · GitHub

fix(IWYU): force std:: or <> for max, min, copy - #411

Merged
aaronliu0130 merged 1 commit into
developfrom
minmaxxing
Nov 27, 2025
Merged

fix(IWYU): force std:: or <> for max, min, copy#411
aaronliu0130 merged 1 commit into
developfrom
minmaxxing

Conversation

Copy link
Copy Markdown
Member

suppress false positive on direct initialization (int max(0);)

Fixes #296

suppress false positive on direct initialization (`int max(0);`)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

This PR fixes a false positive in the Include What You Use (IWYU) checker by preventing direct initialization syntax (like int max(0);) from being incorrectly flagged as requiring #include <algorithm>. The fix moves copy, max, and min from the general template detection pattern to a specialized pattern that only matches when these functions are:

  1. Explicitly qualified with std:: (e.g., std::max(a, b)), OR
  2. Used with template arguments (e.g., max<int>(a, b))

Key Changes

  • Removes copy, max, and min from the _HEADERS_MAYBE_TEMPLATES tuple to prevent the generic pattern from matching them
  • Adds a specialized regex pattern that only matches fully qualified or explicitly templated uses of these three functions
  • Adds a test case to verify that direct initialization syntax doesn't trigger false positives
  • Minor comment improvement for consistency

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cpplint.py Removes copy, max, min from generic template list and adds specialized pattern with stricter matching rules to avoid false positives
cpplint_unittest.py Adds test case verifying that direct initialization syntax (int max(0)) doesn't trigger IWYU warnings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cpplint_unittest.py
""",
"Add #include <algorithm> for min [build/include_what_you_use] [4]",
)
self.TestIncludeWhatYouUse("int max(0), copy(max), min();", "")

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The test case verifies that false positives are suppressed, but there's no corresponding test to verify that legitimate uses of std::max(), std::min(), or std::copy() still trigger the include warning. Consider adding test cases like:

self.TestIncludeWhatYouUse("int x = std::max(a, b);", 
    "Add #include <algorithm> for max  [build/include_what_you_use] [4]")
self.TestIncludeWhatYouUse("std::copy(src.begin(), src.end(), dst.begin());",
    "Add #include <algorithm> for copy  [build/include_what_you_use] [4]")

This ensures the fix doesn't break detection of actual usage.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

How was this resolved? Do those tests already exist or are they not worth adding?

aaronliu0130 Nov 27, 2025
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Indeed, I didn't think they were worth adding—the max and copy regexes are the same as the already-tested one for min, and just like how regexes for max and copy weren't already there, throughout the unit tests each part of the relevant regex pattern is only tested once. Sorry for resolving without leaving this comment.

cclauss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

RSLGTM

aaronliu0130 merged commit 9f4e9df into develop Nov 27, 2025
20 checks passed

Copy link
Copy Markdown
Member Author

Thanks—had to search up what a RS is :)

Could you also check out #376? That's the one I really want to get over with.

cclauss deleted the minmaxxing branch November 27, 2025 18:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

False positive for min and max

3 participants


Back | FazBrowse Home | New Git URL