Commit d94318a5 authored by Andrew Gallagher's avatar Andrew Gallagher Committed by Facebook Github Bot

folly/Preprocessor.h: fix `FB_ANONYMOUS_VARIABLE` in modular builds

Summary:
Modular builds build each module with its own preprocessor state, meaning
`__COUNTER__` no longer provides a unique number across a TU.  Instead of
calling back to just `__LINE__`, use a mix of `__COUNTER__` and `__LINE__`
to try provide as much uniqueness as possible.

Reviewed By: yfeldblum

Differential Revision: D13152221

fbshipit-source-id: e1728d56f793d2f2cc7992056f6049c4c3566c94
parent 6dbd476b
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#pragma once #pragma once
#include <folly/CPortability.h>
/** /**
* Necessarily evil preprocessor-related amenities. * Necessarily evil preprocessor-related amenities.
*/ */
...@@ -87,7 +89,16 @@ ...@@ -87,7 +89,16 @@
#define FB_CONCATENATE_IMPL(s1, s2) s1##s2 #define FB_CONCATENATE_IMPL(s1, s2) s1##s2
#define FB_CONCATENATE(s1, s2) FB_CONCATENATE_IMPL(s1, s2) #define FB_CONCATENATE(s1, s2) FB_CONCATENATE_IMPL(s1, s2)
#ifdef __COUNTER__ #ifdef __COUNTER__
// Modular builds build each module with its own preprocessor state, meaning
// `__COUNTER__` no longer provides a unique number across a TU. Instead of
// calling back to just `__LINE__`, use a mix of `__COUNTER__` and `__LINE__`
// to try provide as much uniqueness as possible.
#if FOLLY_HAS_FEATURE(modules)
#define FB_ANONYMOUS_VARIABLE(str) \
FB_CONCATENATE(FB_CONCATENATE(FB_CONCATENATE(str, __COUNTER__), _), __LINE__)
#else
#define FB_ANONYMOUS_VARIABLE(str) FB_CONCATENATE(str, __COUNTER__) #define FB_ANONYMOUS_VARIABLE(str) FB_CONCATENATE(str, __COUNTER__)
#endif
#else #else
#define FB_ANONYMOUS_VARIABLE(str) FB_CONCATENATE(str, __LINE__) #define FB_ANONYMOUS_VARIABLE(str) FB_CONCATENATE(str, __LINE__)
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment