Skip to content

Commit f516811

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Fix pointer-to-member-function param with ref-qualifier (#56219)
Summary: Pull Request resolved: #56219 Changelog: [Internal] Doxygen has a bug where it incorrectly embeds the parameter name of pointer-to-member-function parameters with ref-qualifiers (& or &&) into the type string instead of providing a separate <declname> element. This caused the snapshot to output `R(folly::dynamic::*)() const asFoo&` instead of the correct `R(folly::dynamic::*asFoo)() const &`. This diff detects the misplaced name in the type string and reconstructs the correct pointer-to-member declarator. Reviewed By: cipolleschi Differential Revision: D98123353 fbshipit-source-id: a3a92c5d3897721f0b97a232fdaa59379b408b29
1 parent 015cd13 commit f516811

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

scripts/cxx-api/parser/builders.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,29 @@ def get_doxygen_params(
377377
param_type[:insert_pos] + param_name + param_type[insert_pos:]
378378
)
379379
param_name = None
380+
else:
381+
# Doxygen bug: for pointer-to-member-function params with
382+
# ref-qualifiers (& or &&), Doxygen incorrectly embeds the
383+
# parameter name in the type string between cv-qualifiers
384+
# and the ref-qualifier, and omits <declname> entirely:
385+
# <type>R(ns::*)() const asFoo &amp;</type>
386+
# Detect this pattern and reconstruct the correct type:
387+
# R(ns::*asFoo)() const &
388+
m = re.search(
389+
r"(\([^)]*::\*\))" # group 1: ptr-to-member declarator
390+
r"(.+?)" # group 2: param list + cv-qualifiers
391+
r"\s+([a-zA-Z_]\w*)" # group 3: misplaced identifier
392+
r"\s*(&{1,2})\s*$", # group 4: ref-qualifier
393+
param_type,
394+
)
395+
if m:
396+
param_type = (
397+
param_type[: m.end(1) - 1] # up to ')' of (ns::*)
398+
+ m.group(3) # insert extracted name
399+
+ param_type[m.end(1) - 1 : m.end(2)] # ')' + params + cv-quals
400+
+ " "
401+
+ m.group(4) # ref-qualifier
402+
)
380403

381404
qualifiers, core_type = extract_qualifiers(param_type)
382405
arguments.append((qualifiers, core_type, param_name, param_default))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct folly::dynamic {
2+
}
3+
4+
5+
template <typename R, typename... T>
6+
R test::jsArg(const folly::dynamic& arg, R(folly::dynamic::*asFoo)() const &, const T &... desc);
7+
template <typename R, typename... T>
8+
R test::jsArg(const folly::dynamic& arg, R(folly::dynamic::*asFoo)() const, const T &... desc);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
namespace folly {
11+
12+
struct dynamic {};
13+
14+
} // namespace folly
15+
16+
namespace test {
17+
18+
template <typename R, typename... T>
19+
R jsArg(const folly::dynamic &arg, R (folly::dynamic::*asFoo)() const, const T &...desc);
20+
template <typename R, typename... T>
21+
R jsArg(const folly::dynamic &arg, R (folly::dynamic::*asFoo)() const &, const T &...desc);
22+
23+
} // namespace test

0 commit comments

Comments
 (0)