Skip to content
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

Use __VA_OPT__(, ) __VA_ARGS__ instead of ##__VA_ARGS__ #11008

Merged
merged 2 commits into from Aug 23, 2022

Conversation

Pokechu22
Copy link
Contributor

Per https://en.cppreference.com/w/cpp/preprocessor/replace#.23_and_.23.23_operators the ## behavior is a nonstandard extension; this extension seems to be supported by all compilers we care about, but IntelliSense in visual studio doesn't correctly handle it, resulting in false errors in the IDE (but not when compiling).

Per https://en.cppreference.com/w/cpp/preprocessor/replace#Function-like_macros C++20 introduced a workaround, where __VA_OPT__(, ) generates a comma if and only if __VA_ARGS__ is non-empty.

This PR replaces all occurrences, with the exception of Externals, DSPSpy (which is not likely to be edited in MSVC and does not target C++20 currently), and JitArm64_Integer.cpp (which uses Function(__VA_ARGS__), and thus does not ever need a comma):

#define CARRY_IF_NEEDED(inst_without_carry, inst_with_carry, ...) \
do \
{ \
if (js.op->wantsCA) \
inst_with_carry(__VA_ARGS__); \
else \
inst_without_carry(__VA_ARGS__); \
} while (0)

Supersedes #9936.

@shuffle2
Copy link
Contributor

shuffle2 commented Aug 23, 2022

cmake can/should set c++20 for all Externals (fwiw msbuild uses c17 and c++latest for all Externals. it's preferable to have them all unified, altho we historically decided to use c++20 instead of "latest" on non-msvc)

We use Dolphin code (specifically Common's ASSERT) from ImGui, and that will use C++20 features in the next commit, so ImGui needs to be built with C++20 for that to work properly.
Per https://en.cppreference.com/w/cpp/preprocessor/replace#.23_and_.23.23_operators the `##` behavior is a nonstandard extension; this extension seems to be supported by all compilers we care about, but IntelliSense in visual studio doesn't correctly handle it, resulting in false errors in the IDE (but not when compiling).

Per https://en.cppreference.com/w/cpp/preprocessor/replace#Function-like_macros C++20 introduced a workaround, where `__VA_OPT__(, )` generates a comma if and only if `__VA_ARGS__` is non-empty.

This PR replaces all occurrences, with the exception of Externals, DSPSpy (which is not likely to be edited in MSVC and does not target C++20 currently), and JitArm64_Integer.cpp (which uses `Function(__VA_ARGS__)`, and thus does not ever need a comma).
Copy link
Contributor

@Dentomologist Dentomologist left a comment

Choose a reason for hiding this comment

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

Fixes IntelliSense and LGTM.

@Pokechu22 Pokechu22 merged commit f18d787 into dolphin-emu:master Aug 23, 2022
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants