Skip to content

fix(npa,npm): keep a typed C++ macro call inside parentheses a method - #1931

Merged
dekobon merged 1 commit into
mainfrom
fix/1829-parenthesised-macro-call
Nov 15, 2026
Merged

dekobon merged 1 commit into
mainfrom
fix/1829-parenthesised-macro-call

Conversation

@dekobon

@dekobon dekobon commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Refs #1829, #1885. Follow-up to #1928.

The bug

A class-scope macro call inside a declarator's parentheses expands to the name and parameter list of a method that returns a pointer to function. npa and npm read it as an attribute on both grammars (cpp and mozcpp):

#define DECL(P) method(int P)
struct A { void (*DECL(S::*p))(int); };   // void (*method(int S::*p))(int);

A reads 1 attribute / 0 methods on main 12f312aa. The truth, and the reading before #1885, is 0 / 1.

Since #1928 the same call outside parentheses (void *DECL(S::*p);) is a method when the declaration writes a type or opens with [[noreturn]]. Inside parentheses the reader asked the first word as unsettled, so the call read as the data member its recovered member pointer would be alone.

Fix

cpp_parenthesized_child_verdict (src/metrics/npa/cpp_declarators.rs) carries the declaration's first word through the parentheses: to a pointer, a reference, a member pointer and a nested pair of parentheses. No other reader changes.

What moves

npa and npm for a typed macro call with a member-pointer argument inside a declarator's parentheses: class_methods rises and class_attributes falls by one, with the values derived from them. No corpus snapshot moves.

Cost and limits, pinned in the tests

  • Data members that read as methods (FIXME(#1829)): an annotation macro inside the parentheses of a pointer to function or to member function, before a parenthesised member pointer, is the tree of the call. int (* MOZ_X (S::*pd))(int); and int (S::* MOZ_X (S::*pd))(int); read as methods, as they did before fix(npa,npm): a parenthesised pointer-to-data-member is counted as a method in C++ #1885.
  • Calls that stay attributes: after a type written as one unknown identifier, T (*DECL(S::*p))(int);, inside parentheses as outside them.
  • Three typedef names the grammars read apart. tree-sitter-cpp reads intmax_t and uintmax_t as identifiers and the Mozcpp fork reads nullptr_t as one. Behind a member pointer inside parentheses, such a grammar recovers intmax_t (S::*DECL(S::*p))(int); as a declaration with no type and reads the call and the annotated data member as data; the other grammar reads both as methods. Each grammar reads these as it did before fix(npa,npm): a parenthesised pointer-to-data-member is counted as a method in C++ #1885; only 12f312aa had the two agree (both read data).

Review

No person has reviewed this pull request. The review skill checklist, astra-review and argon-review read the first version (b5de0a93). argon-review found one untested path (a templated member pointer inside parentheses); astra-review found the grammar difference above and that the CHANGELOG claimed more than holds for those three names. Rows and pins were added; no production code changed. Both reviewers then read the amended commit 390bcbc4 and report no finding.

Evidence

  • On 390bcbc4: make pre-commit gives BCA_GATE: pass (gate=pre-commit); make check-test-lang-gates-compare COMPARE_REF=12f312aa passes; make bench-scaling: all 139 probes within their complexity bound. Two earlier runs failed at a host load average of 50 to 58, on different probes each time (2, then 10), none of them C++ npa or npm; the run that passed was at a load average of about 4.
  • The new test fails without the change (na 17 / nm 0 for na 6 / nm 11). Hand mutations of the changed lines: 5 of 6 fail the expected test. The sixth, a settled first word under a recovered member pointer, changes no reading; argon-review reasons that no input can observe that argument.
  • Generated spellings that g++ and clang++ accept, against 12f312aa, same on both grammars: of 781 macro calls, 50 more read right (629 to 679) and none fewer; of 1,737 data members, 13 fewer read right (1,207 to 1,194), each TYPE (* MOZ_X (S::*pd))(int) with or without = nullptr, and each read as a method at e689d658 too.
  • 2,980 real files (293 system headers that contain ::*; 2,687 C++ files of mozilla/gecko-dev at 5836a062; 8,244 classes): no class differs between 12f312aa and 390bcbc4.
  • Release builds of 12f312aa and 390bcbc4 over the local fixture tree: 6,649 files (12,414 runs, both grammars), 97 runs differ and none changes status. All 3,333 class readings that moved go from attribute to method. 3,329 equal the reading of e689d658; the other 4 are in two token-mutated files that are not C++.

A class-scope macro call inside a declarator's parentheses expands to
the name and parameter list of a method that returns a pointer to
function:

    #define DECL(P) method(int P)
    struct A { void (*DECL(S::*p))(int); };
    // void (*method(int S::*p))(int);
    // truth 0 attributes / 1 method; before this commit 1 / 0;
    // before #1885 0 / 1

The call is a `function_declarator` named `DECL` whose parameter list
is a recovered member pointer, under a `pointer_declarator` inside a
`parenthesized_declarator`. Outside parentheses the same node is a
method when the declaration writes a type or opens with `[[noreturn]]`
(`void *DECL(S::*p);`, #1928). Inside them the first word was asked as
unsettled, so the call read as the data member its recovery would be
alone. `cpp_parenthesized_child_verdict` now carries the declaration's
first word through the parentheses, to a pointer, a reference, a member
pointer and a nested pair alike.

The cost is one family of data members. An annotation macro inside the
parentheses of a pointer to function or to member function, before a
parenthesised member pointer, is the tree of the call:
`int (* MOZ_X (S::*pd))(int);` and `int (S::* MOZ_X (S::*pd))(int);`
read as methods, as they did before #1885. Pinned FIXME(#1829). A call
after a type written as a lone identifier stays an attribute inside
parentheses as outside them (`T (*DECL(S::*p))(int);`, pinned).

Behind a member pointer inside parentheses the two grammars part on
three typedef names, as they did before #1885 and did not at 12f312a.
tree-sitter-cpp reads `intmax_t` and `uintmax_t` as identifiers and
the Mozcpp fork reads `nullptr_t` as one. Such a grammar recovers
`intmax_t (S::*DECL(S::*p))(int);` as a declaration with no type, where
no first word is settled, and reads the call and the annotated data
member `intmax_t (S::* MOZ_X (S::*pd))(int);` as data; the other
grammar reads both as methods. Pinned per grammar.

On generated spellings that g++ and clang++ accept, against 12f312a:
of 781 macro calls, 50 more read right (629 to 679) and none fewer; of
1,737 data members, 13 fewer read right (1,207 to 1,194), each of them
`TYPE (* MOZ_X (S::*pd))(int)` with or without `= nullptr`, and each
read as a method at e689d65 too.

Tests: `PARENTHESISED_MACRO_CALLS_WITH_MEMBER_POINTERS` (na 6 / nm 11;
without the change na 17 / nm 0). The pin
`PARENTHESISED_TYPED_MACRO_CALL_WITH_MEMBER_POINTER` is gone with the
misreading it recorded; `ANNOTATION_INSIDE_PARENTHESES_BEFORE_MEMBER_POINTER`
pins the cost, and `INTMAX_T_…` and
`NULLPTR_T_BEFORE_PARENTHESISED_MEMBER_POINTERS` the two grammars'
readings.

Refs #1829 #1885
@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.57%. Comparing base (12f312a) to head (390bcbc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1931   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         407      407           
  Lines      127233   127276   +43     
  Branches   126798   126841   +43     
=======================================
+ Hits       125420   125463   +43     
  Misses       1088     1088           
  Partials      725      725           
Flag Coverage Δ
python 100.00% <ø> (ø)
rust 98.57% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/metrics/npa/cpp_declarators.rs 98.81% <100.00%> (+0.02%) ⬆️
src/metrics/npm.rs 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dekobon
dekobon merged commit 390bcbc into main Nov 15, 2026
54 checks passed
@dekobon
dekobon deleted the fix/1829-parenthesised-macro-call branch November 16, 2026 15:02

This branch was successfully deployed

1 active deployment
github-pages — 390bcbc4 Deployed Nov 15, 2026 by dekobon via deploy to GitHub Pages #1088
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.

1 participant