Skip to content

Conversation

@egorzhdan
Copy link
Contributor

ClangImporter has logic that infers default arguments of certain C/C++ types, such as the types declared via CF_OPTIONS/NS_OPTIONS macros.

There were some workarounds in place which triggered for C++ interop mode specifically. The workarounds were applying a heuristic based on the name of the type, which tried to match the behavior to non-C++ interop mode for certain types from the OS SDK. That was not working well for user-defined types, causing source compatibility breakages when enabling C++ interop.

This change replaces the name-based heuristic with a more robust criteria.

See also 3791ccb.

rdar://142961112

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Mar 10, 2025
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

1 similar comment
@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could use LLVM's StringSwitch (https://llvm.org/doxygen/classllvm_1_1StringSwitch.html). But this is just two strings so maybe it does not make a difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

ClangImporter has logic that infers default arguments of certain C/C++ types, such as the types declared via `CF_OPTIONS`/`NS_OPTIONS` macros.

There were some workarounds in place which triggered for C++ interop mode specifically. The workarounds were applying a heuristic based on the name of the type, which tried to match the behavior to non-C++ interop mode for certain types from the OS SDK. That was not working well for user-defined types, causing source compatibility breakages when enabling C++ interop.

This change replaces the name-based heuristic with a more robust criteria.

See also 3791ccb.

rdar://142961112
@egorzhdan egorzhdan force-pushed the egorzhdan/nsoptions-name-based branch from 249e3ee to 5b7c595 Compare March 11, 2025 12:47
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan merged commit 9560b86 into main Mar 11, 2025
3 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/nsoptions-name-based branch March 11, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ interop Feature: Interoperability with C++

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants