Skip to content

Commit bf4978e

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Fix trailing return type in virtual functions (react#55644)
Summary: Pull Request resolved: react#55644 Changelog: [Internal] Updates the C++ api snapshot generator to correctly handle trailing return types for pure virtual functions. Reviewed By: cipolleschi Differential Revision: D93407597 fbshipit-source-id: c0bd00752fa69eea6c75933adba7a5782a74e90d
1 parent f013533 commit bf4978e

4 files changed

Lines changed: 45 additions & 4 deletions

File tree

scripts/cxx-api/parser/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import annotations
77

88
import os
9+
import re
910
from pprint import pprint
1011

1112
from doxmlparser import compound, index
@@ -246,10 +247,13 @@ def get_function_member(
246247
function_name = function_def.get_name()
247248
function_type = resolve_ref_text_name(function_def.get_type())
248249
function_arg_string = function_def.get_argsstring()
249-
function_virtual = (
250-
function_def.get_virt() == "virtual"
251-
or function_def.get_virt() == "pure-virtual"
252-
)
250+
is_pure_virtual = function_def.get_virt() == "pure-virtual"
251+
function_virtual = function_def.get_virt() == "virtual" or is_pure_virtual
252+
253+
# Doxygen incorrectly merges "=0" into the return type for pure-virtual
254+
# functions using trailing return types (e.g. "auto f() -> T = 0").
255+
# Strip the trailing "=0" from the type string.
256+
function_type = re.sub(r"\s*=\s*0\s*$", "", function_type)
253257

254258
doxygen_params = get_doxygen_params(function_def)
255259

@@ -259,6 +263,7 @@ def get_function_member(
259263
visibility,
260264
function_arg_string,
261265
function_virtual,
266+
is_pure_virtual,
262267
is_static,
263268
doxygen_params,
264269
)

scripts/cxx-api/parser/member.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def __init__(
166166
visibility: str,
167167
arg_string: str,
168168
is_virtual: bool,
169+
is_pure_virtual: bool,
169170
is_static: bool,
170171
doxygen_params: list[Argument] | None = None,
171172
) -> None:
@@ -178,6 +179,12 @@ def __init__(
178179
doxygen_params if doxygen_params is not None else parsed_arguments
179180
)
180181

182+
# Doxygen signals pure-virtual via the virt attribute, but the arg string
183+
# may not contain "= 0" (e.g. trailing return type syntax), so the
184+
# modifiers parsed from the arg string may miss it. Propagate the flag.
185+
if is_pure_virtual:
186+
self.modifiers.is_pure_virtual = True
187+
181188
self.is_const = self.modifiers.is_const
182189
self.is_override = self.modifiers.is_override
183190

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class test::Base {
2+
public virtual const char * getName() = 0;
3+
public virtual std::vector< test::Method > getMethods() = 0;
4+
}
5+
6+
struct test::Method {
7+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#include <vector>
11+
12+
namespace test {
13+
14+
struct Method {};
15+
16+
class Base {
17+
public:
18+
virtual auto getMethods() -> std::vector<Method> = 0;
19+
virtual auto getName() -> const char * = 0;
20+
};
21+
22+
} // namespace test

0 commit comments

Comments
 (0)