KhronosGroup / KhronosGroup/Vulkan-Samples

Clang format check not properly working for code behind compiler directives

Open
#1,537 2 comments 0 reactions 0 assignees View on GitHub
build
Dominant language
C++
Stars
5.4k
Forks
835
Avg merge
2h 16m
Merged PRs (30d)
1

Description

I've been battling Clang format for a larger PR and it seems that the Clang format check is not properly working for code that is guarded by a compiler define.

E.g. this code:

```cpp
#ifdef SOMETHING
#else
VkRenderPassBeginInfo render_pass_begin_info = vkb::initializers::render_pass_begin_info();
render_pass_begin_info.renderPass = render_pass;
render_pass_begin_info.renderArea.offset.x = 0;
render_pass_begin_info.renderArea.offset.y = 0;
render_pass_begin_info.renderArea.extent.width = width;
render_pass_begin_info.renderArea.extent.height = height;
render_pass_begin_info.clearValueCount = 5;
render_pass_begin_info.pClearValues = clear_values;
render_pass_begin_info.framebuffer = framebuffers[current_image_index];
#endif
```

Triggers a Clang format CI failrure, even though the formatting was chnaged like that Clang format itself. And this looks exactly like our formatting guidelines

Reverting this by hand to look like this:

```cpp
#ifdef SOMETHING
#else
VkRenderPassBeginInfo render_pass_begin_info = vkb::initializers::render_pass_begin_info();
render_pass_begin_info.renderPass = render_pass;
render_pass_begin_info.renderArea.offset.x = 0;
render_pass_begin_info.renderArea.offset.y = 0;
render_pass_begin_info.renderArea.extent.width = width;
render_pass_begin_info.renderArea.extent.height = height;
render_pass_begin_info.clearValueCount = 5;
render_pass_begin_info.pClearValues = clear_values;
render_pass_begin_info.framebuffer = framebuffers[current_image_index];
```

Fixes CI.

IMO that's wrong and needs to be fixed, otherwise every time I do a local Clang format for files changed I need to wait for CI to fail, decipher a cryptic message and manually fix stuff again.

Contributor guide

Open the contributing guide

Research direction

Start by inspecting the repository's Clang-format check configuration and the CI entry point that formats changed C++ files. Reproduce the check with the shown #ifdef/#else snippet, then verify that locally formatted code behind compiler directives passes CI without manual reformatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
ci-cd, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.