Skip to content

[DNM] c++: showcase gen_defines.py macro expansion issue #86770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tests/lib/cpp/cxx/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*
* Application overlay for creating a fake device instance we can use to
* test. Subset of tests/kernel/device/app.overlay and other app.overlay
* files.
* test. Nested devices have been used to avoid cross-platform issues by
* forcing a specific 'reg' property size on child nodes.
*/

/ {
Expand All @@ -20,4 +20,18 @@

zephyr,deferred-init;
};

test_ctrl: ctrl {
compatible = "fake-cpp-driver";
status = "okay";

#address-cells = < 1 >;
#size-cells = < 0 >;

test_dev2_reg_addr: dev2@2 {
reg = < 2 >;
compatible = "fake-cpp-driver";
status = "okay";
};
};
};
19 changes: 19 additions & 0 deletions tests/lib/cpp/cxx/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,22 @@ PM_DEVICE_DT_DEFINE(DT_NODELABEL(test_dev0_boot), fake_pm_action);

DEVICE_DT_DEFINE(DT_NODELABEL(test_dev0_boot), NULL,
PM_DEVICE_DT_GET(DT_NODELABEL(test_dev0_boot)), NULL, NULL, POST_KERNEL, 34, NULL);

/*
* Test preprocessor comment removal. The reg value is defined as 2 in the
* device tree, but gen_defines.py by default outputs an entry that includes a
* trailing comment, such as:
*
* #define DT_N_S_ctrl_S_dev2_2_REG_IDX_0_VAL_ADDRESS 2 / * 0x2 * /
*
* That comment, when present, confuses the C++ preprocessor and results in
* issues like the following:
*
* error: pasting "/ * 0x2 * /" and "U" does not give a valid preprocessing token
*
* or, in this synthetic test case:
*
* error: unable to find numeric literal operator 'operator""UU'
*/
#define VALUE_FROM_DT DT_REG_ADDR(DT_NODELABEL(test_dev2_reg_addr))
BUILD_ASSERT(UINT32_C(VALUE_FROM_DT) == 2U);
Loading