Skip to content

Commit 3f28bd7

Browse files
committed
Add work-around for VA_ARGS_NARGS() on MSVC.
The previous coding of VA_ARGS_NARGS() always returned 1 on Visual Studio, because it treats __VA_ARGS__ as a single token unless you jump through extra hoops. Newer compilers have an option to fix that. Add a comment about that so that we can remember to clean this up in the future when our minimum MSVC version advances. Author: Victor Spirin <v.spirin@postgrespro.ru> Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/f450fc57-a147-19d0-e50c-33571c52cc13%40postgrespro.ru
1 parent 01be9d4 commit 3f28bd7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/include/c.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,25 @@
324324
* pretty trivial: VA_ARGS_NARGS_() returns its 64th argument, and we set up
325325
* the call so that that is the appropriate one of the list of constants.
326326
* This idea is due to Laurent Deniau.
327+
*
328+
* MSVC has an implementation of __VA_ARGS__ that doesn't conform to the
329+
* standard unless you use the /Zc:preprocessor compiler flag, but that
330+
* isn't available before Visual Studio 2019. For now, use a different
331+
* definition that also works on older compilers.
327332
*/
333+
#ifdef _MSC_VER
334+
#define EXPAND(args) args
335+
#define VA_ARGS_NARGS(...) \
336+
VA_ARGS_NARGS_ EXPAND((__VA_ARGS__, \
337+
63,62,61,60, \
338+
59,58,57,56,55,54,53,52,51,50, \
339+
49,48,47,46,45,44,43,42,41,40, \
340+
39,38,37,36,35,34,33,32,31,30, \
341+
29,28,27,26,25,24,23,22,21,20, \
342+
19,18,17,16,15,14,13,12,11,10, \
343+
9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
344+
#else
345+
328346
#define VA_ARGS_NARGS(...) \
329347
VA_ARGS_NARGS_(__VA_ARGS__, \
330348
63,62,61,60, \
@@ -334,6 +352,8 @@
334352
29,28,27,26,25,24,23,22,21,20, \
335353
19,18,17,16,15,14,13,12,11,10, \
336354
9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
355+
#endif
356+
337357
#define VA_ARGS_NARGS_( \
338358
_01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
339359
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy