@@ -120,37 +120,45 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
120120// MSVC requires special handling here.
121121#ifndef _MSC_VER
122122
123- #if __has_feature(cxx_alignas)
124- #define POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (x ) \
125- template <> struct AlignedCharArrayImpl <x> \
126- { \
127- char alignas (x) aligned; \
128- }
123+ #ifdef POCO_COMPILER_CLANG
124+
125+ #if __has_feature(cxx_alignas)
126+ #define POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (x ) \
127+ template <> struct AlignedCharArrayImpl <x> \
128+ { \
129+ char alignas (x) aligned; \
130+ }
131+ #define POCO_HAVE_ALIGNMENT
132+ #endif
133+
129134 #elif defined(__GNUC__) || defined(__IBM_ATTRIBUTES)
135+
130136 #define POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (x ) \
131137 template <> struct AlignedCharArrayImpl <x> \
132138 { \
133139 char aligned __attribute__ ((aligned(x))); \
134140 }
135- #else
136- # error No supported align as directive.
137- #endif
138-
139- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (1 );
140- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (2 );
141- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (4 );
142- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (8 );
143- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (16 );
144- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (32 );
145- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (64 );
146- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (128 );
147- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (512 );
148- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (1024 );
149- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (2048 );
150- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (4096 );
151- POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (8192 );
141+ #define POCO_HAVE_ALIGNMENT
152142
153- #undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
143+ #endif
144+
145+ #ifdef POCO_HAVE_ALIGNMENT
146+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (1 );
147+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (2 );
148+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (4 );
149+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (8 );
150+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (16 );
151+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (32 );
152+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (64 );
153+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (128 );
154+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (512 );
155+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (1024 );
156+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (2048 );
157+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (4096 );
158+ POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT (8192 );
159+
160+ #undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
161+ #endif // POCO_HAVE_ALIGNMENT
154162
155163#else // _MSC_VER
156164
@@ -180,49 +188,59 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
180188 // Any larger and MSVC complains.
181189 #undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
182190
191+ #define POCO_HAVE_ALIGNMENT
183192#endif // _MSC_VER
184193
194+ // POCO_HAVE_ALIGNMENT will be defined on the pre-C++11 platforms/compilers where
195+ // it can be reliably determined and used. Uncomment the line below to explicitly
196+ // disable use of alignment even for those platforms.
197+ // #undef POCO_HAVE_ALIGNMENT
185198
186- template <typename T1 , typename T2 = char , typename T3 = char , typename T4 = char >
187- union AlignedCharArrayUnion
188- // / This union template exposes a suitably aligned and sized character
189- // / array member which can hold elements of any of up to four types.
190- // /
191- // / These types may be arrays, structs, or any other types. The goal is to
192- // / produce a union type containing a character array which, when used, forms
193- // / storage suitable to placement new any of these types over. Support for more
194- // / than four types can be added at the cost of more boiler plate.
195- {
196- private:
197- class AlignerImpl
198- {
199- T1 t1;
200- T2 t2;
201- T3 t3;
202- T4 t4;
203-
204- AlignerImpl (); // Never defined or instantiated.
205- };
206199
207- union SizerImpl
208- {
209- char arr1[sizeof (T1 )];
210- char arr2[sizeof (T2 )];
211- char arr3[sizeof (T3 )];
212- char arr4[sizeof (T4 )];
213- };
200+ #ifdef POCO_HAVE_ALIGNMENT
214201
215- public:
216- char buffer[sizeof (SizerImpl)];
217- // / The character array buffer for use by clients.
202+ template <typename T1 , typename T2 = char , typename T3 = char , typename T4 = char >
203+ union AlignedCharArrayUnion
204+ // / This union template exposes a suitably aligned and sized character
205+ // / array member which can hold elements of any of up to four types.
218206 // /
219- // / No other member of this union should be referenced. They exist purely to
220- // / constrain the layout of this character array.
207+ // / These types may be arrays, structs, or any other types. The goal is to
208+ // / produce a union type containing a character array which, when used, forms
209+ // / storage suitable to placement new any of these types over. Support for more
210+ // / than four types can be added at the cost of more boiler plate.
211+ {
212+ private:
213+ class AlignerImpl
214+ {
215+ T1 t1;
216+ T2 t2;
217+ T3 t3;
218+ T4 t4;
219+
220+ AlignerImpl (); // Never defined or instantiated.
221+ };
222+
223+ union SizerImpl
224+ {
225+ char arr1[sizeof (T1 )];
226+ char arr2[sizeof (T2 )];
227+ char arr3[sizeof (T3 )];
228+ char arr4[sizeof (T4 )];
229+ };
230+
231+ public:
232+ char buffer[sizeof (SizerImpl)];
233+ // / The character array buffer for use by clients.
234+ // /
235+ // / No other member of this union should be referenced. They exist purely to
236+ // / constrain the layout of this character array.
237+
238+ private:
239+ Poco::AlignedCharArrayImpl<AlignOf<AlignerImpl>::Alignment> _nonceMember;
221240
222- private:
223- Poco::AlignedCharArrayImpl<AlignOf<AlignerImpl>::Alignment> _nonceMember;
224241};
225242
243+ #endif // POCO_HAVE_ALIGNMENT
226244
227245} // namespace Poco
228246
0 commit comments