From 1fdddb09fe948993f736ed230ff06b5763560a44 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 3 Mar 2026 01:00:16 -0800 Subject: [PATCH] Fix double constexpr in constructors (#55846) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55846 Changelog: [Internal] When constructors are marked as "constexpr", doxygen will output them as a function of type "constexpr" with "is-constexpr=yes". This causes the script to duplicate the keyword. This diff fixes that by explicitly covering this edge case. Reviewed By: cipolleschi Differential Revision: D94901507 fbshipit-source-id: 384513381a86ba2efe07f14fd5976216ea5a8572 --- scripts/cxx-api/parser/main.py | 6 ++++++ .../snapshot.api | 6 ++++++ .../test.h | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_constexpr_constructor/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_constexpr_constructor/test.h diff --git a/scripts/cxx-api/parser/main.py b/scripts/cxx-api/parser/main.py index 394ecb7027a..f6e991fbb6b 100644 --- a/scripts/cxx-api/parser/main.py +++ b/scripts/cxx-api/parser/main.py @@ -324,6 +324,12 @@ def get_function_member( # Strip the trailing "=0" from the type string. function_type = re.sub(r"\s*=\s*0\s*$", "", function_type) + # For constexpr constructors, Doxygen outputs "constexpr" both as an + # attribute (constexpr="yes") and as the return type (constexpr). + # Remove the redundant type to avoid "constexpr constexpr" in output. + if is_constexpr and function_type == "constexpr": + function_type = "" + doxygen_params = get_doxygen_params(function_def) function = FunctionMember( diff --git a/scripts/cxx-api/tests/snapshots/should_handle_constexpr_constructor/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_constexpr_constructor/snapshot.api new file mode 100644 index 00000000000..3dfabf6f9e3 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_constexpr_constructor/snapshot.api @@ -0,0 +1,6 @@ +class test::Clss { + public constexpr Clss() = default; + public constexpr Clss(const test::Clss&) = default; + public constexpr Clss(int value); + public constexpr Clss(test::Clss&&) = default; +} diff --git a/scripts/cxx-api/tests/snapshots/should_handle_constexpr_constructor/test.h b/scripts/cxx-api/tests/snapshots/should_handle_constexpr_constructor/test.h new file mode 100644 index 00000000000..4694db51244 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_constexpr_constructor/test.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +namespace test { + +class Clss { + public: + constexpr Clss() = default; + constexpr Clss(const Clss &) = default; + constexpr Clss(Clss &&) = default; + explicit constexpr Clss(int value); +}; + +} // namespace test