File tree Expand file tree Collapse file tree
tests/snapshots/should_handle_pure_virtual_trailing_return Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66from __future__ import annotations
77
88import os
9+ import re
910from pprint import pprint
1011
1112from 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 )
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments