From 5809adc5cdaad64d1a73458e6c3fa19d6823cd83 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 10 Mar 2026 06:37:32 -0700 Subject: [PATCH] Fix ordering of `const` and `mutable` keywords (#56027) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56027 Changelog: [Internal] The current implementation swaps the ordering of `const` and `mutable` keywords. This diff fixes it. Differential Revision: D95912404 --- scripts/cxx-api/parser/member.py | 6 +++--- .../snapshot.api | 5 +++++ .../test.h | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_mutable_const_pointer_ordering/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_mutable_const_pointer_ordering/test.h diff --git a/scripts/cxx-api/parser/member.py b/scripts/cxx-api/parser/member.py index 3fd415f2d229..92a5c8631e6f 100644 --- a/scripts/cxx-api/parser/member.py +++ b/scripts/cxx-api/parser/member.py @@ -171,12 +171,12 @@ def to_string( if self.is_constexpr: result += "constexpr " - if self.is_const and not self.is_constexpr: - result += "const " - if self.is_mutable: result += "mutable " + if self.is_const and not self.is_constexpr: + result += "const " + if self._is_function_pointer(): formatted_args = format_arguments(self._fp_arguments) qualified_type = format_parsed_type(self._parsed_type) diff --git a/scripts/cxx-api/tests/snapshots/should_handle_mutable_const_pointer_ordering/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_mutable_const_pointer_ordering/snapshot.api new file mode 100644 index 000000000000..2066064f32f6 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_mutable_const_pointer_ordering/snapshot.api @@ -0,0 +1,5 @@ +class test::Cache { + public const int* constPtr; + public mutable const int* mutableConstPtr; + public mutable int* mutablePtr; +} diff --git a/scripts/cxx-api/tests/snapshots/should_handle_mutable_const_pointer_ordering/test.h b/scripts/cxx-api/tests/snapshots/should_handle_mutable_const_pointer_ordering/test.h new file mode 100644 index 000000000000..06b03e665c32 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_mutable_const_pointer_ordering/test.h @@ -0,0 +1,19 @@ +/* + * 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 Cache { + public: + mutable int *mutablePtr; + const int *constPtr; + mutable const int *mutableConstPtr; +}; + +} // namespace test