Skip to content

diagnose comparisons between two arrays (P2865), fix for [GH #370] - #387

Open
mohitmishra786 wants to merge 2 commits into
edgcpp:mainfrom
mohitmishra786:gh-370-array-comparisons
Open

mohitmishra786 wants to merge 2 commits into
edgcpp:mainfrom
mohitmishra786:gh-370-array-comparisons

Conversation

@mohitmishra786

@mohitmishra786 mohitmishra786 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #370.

A comparison between two arrays with ==, !=, <, <=, > or >= was accepted silently in every mode. It is deprecated in C++20 and not allowed in C++26 (P2865).

process_eq_operator and process_rel_operator now call check_for_array_comparison before the array-to-pointer conversion (the same place <=> already rejects two arrays). If both operands have array type:

  • C++26: error, "comparison between two arrays is not allowed".
  • C++20 and C++23: warning, "comparison between two arrays is deprecated".
  • When emulating GCC before 15 or Clang before 20, C++26 only gets the warning. GCC 14 warns and GCC 15 errors with -std=c++26 (checked with the gcc:14 and gcc:15 images); Clang implemented P2865 in Clang 20.

A comparison between an array and a pointer is not affected.

Summary by CodeRabbit

Bug Fixes

  • Comparisons between two arrays using equality or relational operators now produce deprecation warnings in C++20 and C++23, and errors in C++26.
  • In compatibility modes for older GCC and Clang versions, these comparisons continue to produce warnings rather than errors.
  • Comparisons between an array and a pointer remain allowed.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8f6bcb1e-6eeb-4355-b8c0-785b2fb48e45
Commits

Reviewing files that changed from the base of the PR and between d5a1e7d and 0d4eabd.

Files ignored due to path filters: 1
  • tests/expectations/edg_x86_64/imported.log is excluded by !**/*.log
Files selected for processing: 9
  • tests/tests/imported/clang/cpp/SemaCXX/.deprecated.rto/default.8.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.deprecated.rto/default.9.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.self-comparison.rto/default.1.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.self-comparison.rto/default.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.warn-array-comparion.rto/default.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.warn-array-comparion.rto/default.3.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.warn-array-comparion.rto/default.4.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.warn-self-comparisons.rto/default.2.1.txt
  • tests/tests/imported/clang/cpp/SemaCXX/.warn-self-comparisons.rto/default.3.1.txt

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The compiler now diagnoses built-in equality and relational comparisons between two arrays. The diagnostic depends on the C++ standard and, in C++26 mode, the emulated compiler version. Tests also cover comparisons between an array and a pointer.

Changes: Array comparison diagnostics

Layer / File(s) Summary
Diagnostic check and operator integration
src/error_msg.txt, src/expr.c
The built-in equality and relational operator paths check the original operands for two array types. C++20 and C++23 produce deprecation warnings. C++26 produces errors, except when emulating GCC versions before 15 or Clang versions before 20, which produce warnings.
Standard and compiler-version coverage
tests/tests/changes/GH370*.sft.cpp, tests/tests/changes/.GH370*.rto/*, tests/tests/imported/clang/cpp/SemaCXX/*, src/pending_changes/gh-370-array-comparisons.txt
Tests cover equality and relational comparisons between arrays, array-to-pointer comparisons, and expected diagnostics across language modes and compiler versions. The pending-change note describes the diagnostic conditions.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Merge Risk: Minimal · up to 0d4ea

The implementation is mergeable; the remaining untested combinations are optional coverage improvements rather than demonstrated failures.

Architecture risk: Low · up to 0d4ea

The change affects 2 systems.

Changed systems: tests, src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — tests (service) was modified; 18 changed files map to changed impact.
  • observed — src (service) was modified; 3 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/error_msg.txt: Added diagnostic entries for deprecated and disallowed comparisons between two arrays.
  • observed — Modified behavior in src/expr.c: Added check_for_array_comparison, which checks for two array-typed operands in C++20 mode and diagnoses the comparison. In C++26 mode, it emits an error except on GCC 15+ and Clang 20+, where it emits a deprecation warning.
  • observed — Modified behavior in src/expr.c: The built-in relational-operator path now checks the original operands for an array comparison before operand transformations.
  • observed — Modified behavior in src/expr.c: The built-in equality-operator path now checks the original operands for an array comparison before operand transformations.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: diagnosing comparisons between two arrays under P2865, with a reference to the related issue.
Linked Issues check Passed Issue #370 requires implementing P2865R6, which removes deprecated array comparisons from C++26. The coding requirement is to diagnose comparisons between two arrays using ==, !=, <, <=, >, and >=.

E…
Out of Scope Changes check Passed All changed files relate to the array-comparison diagnostic for #370:
- src/expr.c: the new check and its call sites in the relational and equality paths.
- src/error_msg.txt: the two new diagnostic m…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Linked Issues check

Explanation

Issue #370 requires implementing P2865R6, which removes deprecated array comparisons from C++26. The coding requirement is to diagnose comparisons between two arrays using ==, !=, <, <=, >, and >=.

Evidence from the whole-PR summary (merge base 35b7c47 to head 0d4eabd):

  • src/expr.c adds check_for_array_comparison. It runs in the built-in paths of process_eq_operator and process_rel_operator, before array-to-pointer conversion. When both operands have array type, C++20 and C++23 produce a deprecation warning. C++26 produces an error.
  • src/error_msg.txt adds ec_array_comparison_deprecated and ec_array_comparison_not_allowed.
  • Test fixtures under tests/tests/changes/.GH370* and GH370*.sft.cpp cover ==, !=, <, and >= between arrays. They expect warnings in C++20, errors in C++26, and no diagnostic for array-to-pointer comparisons.
  • Test fixtures show GNU 150000 (GCC 15) and Clang 200000 with C++26 producing errors. Clang 190000 with C++26 produces warnings. This matches the PR description.

The raw summary says C++26 errors apply unless the compiler is GCC 15 or later or Clang 20 or later. That wording conflicts with the PR description and the fixtures, which both place the warning-only exception before GCC 15 and Clang 20. The fixtures support the PR description. This conflict affects only the emulation exception. It does not affect the core C++26 error or C++20 and C++23 warning requirements.

No incremental diff from d5a1e7d was available. This assessment uses the whole-PR summary and the existing test evidence. The core requirement is met.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the array-comparison diagnostic for #370:

  • src/expr.c: the new check and its call sites in the relational and equality paths.
  • src/error_msg.txt: the two new diagnostic messages.
  • src/pending_changes/[GNATS 27773] C++26: Remove Deprecated Array Comparisons from C++26 (P2865R6) #370-array-comparisons.txt: the required pending-change note.
  • tests/tests/changes/.GH370* and GH370*.sft.cpp: regression fixtures for the new diagnostics.
  • tests/tests/imported/clang/cpp/SemaCXX/.deprecated.rto, .self-comparison.rto, .warn-array-comparion.rto, and .warn-self-comparisons.rto: updated expected output. These updates record the new deprecation or error text for existing array-to-array comparisons. They follow directly from the new diagnostics.

No unrelated change is evident in the summary. tests/expectations/edg_x86_64/imported.log is in ignored_files and was not inspected. Its exclusion does not affect this verdict.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (9 skipped: 9 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for d5a1e7d07c57:

@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/expr.c 80.00% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 0d4eabd027be:

CI success.

This branch has not been deployed

No deployments
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.

[GNATS 27773] C++26: Remove Deprecated Array Comparisons from C++26 (P2865R6)

2 participants