adding support for empty argument list in VA_NARGS_COUNT().
(This is not currently used, but it's a feature I'm hoping to use in an upcoming patch.)
Differential D14947
Add support for `VA_NARGS_COUNT() == 0` Authored by Loren Osborn (linux_dr) on May 15 2022, 8:16 PM.
Details
adding support for empty argument list in VA_NARGS_COUNT(). (This is not currently used, but it's a feature I'm hoping to use in an upcoming patch.)
Diff Detail
Event TimelineComment Actions I'm not sure if this fix is compatible with all compilers. Please test and note your compiler and if this fails to compile. (I have added a test to make failure quick and easily detectable.) Comment Actions Status Update: I think the best strategy for handling the MSC case and the case with no similar preprocessor extension is to use an ISEMPTY() implementation similar to the one described here: https://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments/ This all seems like a good deal of effort for a feature that is currently not used. Recommendation: At least for now, I think the most straightforward fix for this is to rename the macro to make it clear that it only supports 1 or more argument. If we need more sophistication in the future, we can add that. Comment Actions Updated this diff to work on all compilers I was able to test it on. Additionally exposed the following new macros:
Comment Actions This is verbose and difficult enough to predict how changes might impact different compilers, that I'd want to see the use case for it's inclusion. We might even consider using a dummy argument as an alternative since this considerably increases the complexity of the VA_NARGS_COUNT macro. I'd rather put this patch on hold until the use case for it is shown. Comment Actions I'm actually working on a use case, fixing some memory alignment issues, but it's still in mid development. After it became apparent that this was a non-trivial fix, I brought it to @Ray Molenkamp (LazyDodo) 's attention. (He was kind of exasperated from my chasing theoretical issues.) I suggested, for now, changing the macro name (by appending _GTE1 or _AT_LEAST_ONE to the macro name) until the empty arguments case was needed. That's when he suggested I bring the diff to your attention. This issue isn't that this fails to build with no arguments; it's simply that it returns the wrong value. (1 instead of 0). To the preprocessor an "empty" argument is just as valid as any other argument, so when counting the empty argument still counts as 1. From the 2010 Jens Gustedt article linked in the diff: I agree it isn't urgently needed at this time, though I've tried to include lots of tests so we have a high degree of confidence in it after it compiles. Ray also mentioned that an administrator could kick off a cross-platform build (for supported platforms) on unmerged patches. This would be helpful to know that all supported compilers are passing these tests. As soon as I have a patch that relies on these changes, I'll let you know. Comment Actions It seems thoroughly covered by tests, that i like, kicked off a build to see how all compilers like it Comment Actions I’m glad we found a failure I can fix, but from the logs, I have no idea what compiler /opt/rh/devtoolset-9/root/usr/bin/c++ is, so I’m not sure how to reproduce the problem. Do you happen to know what compiler this is? Comment Actions it's gcc 9.3.1. on centos7 -- Building in CentOS 7 64bit environment -- The C compiler identification is GNU 9.3.1 -- The CXX compiler identification is GNU 9.3.1 -- Check for working C compiler: /opt/rh/devtoolset-9/root/usr/bin/cc -- Check for working C compiler: /opt/rh/devtoolset-9/root/usr/bin/cc - works Comment Actions but no need to get picky on the gcc version by the looks of it, it seems to repro on all GCC versions Comment Actions Ok, great… that’s exactly the information I needed, I’ve seen this issue before and don’t have a fix yet, but i have a solid way forward now. Thanks! Comment Actions GCC comma token-paste detection was backwards
Comment Actions Probably 100% irrelevant, but this delta helped me discover/report this defect: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105732 (Not blocked) |