Skip to content

Commit 2823749

Browse files
committed
gcc alignment and warning suppression
1 parent d8de748 commit 2823749

31 files changed

Lines changed: 394 additions & 127 deletions

‎Foundation/include/Poco/Alignment.h‎

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎Foundation/include/Poco/Platform_POSIX.h‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@
7575
#define __THROW
7676
#endif
7777
#endif
78+
79+
//
80+
// GCC diagnostics enable/disable by Patrick Horgan, see
81+
// http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
82+
// use example: GCC_DIAG_OFF(unused-variable)
83+
//
84+
#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
85+
#define GCC_DIAG_STR(s) #s
86+
#define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
87+
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
88+
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
89+
#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
90+
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
91+
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
92+
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
93+
#else
94+
#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
95+
#define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(warning GCC_DIAG_JOINSTR(-W,x))
96+
#endif
97+
#else
98+
#define GCC_DIAG_OFF(x)
99+
#define GCC_DIAG_ON(x)
100+
#endif
78101
#endif // __GNUC__
79102

80103

‎Foundation/src/Unicode.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
extern "C"
4141
{
4242
#include "pcre_config.h"
43+
GCC_DIAG_OFF(unused-function) // pcre_memmove unused function warning
4344
#include "pcre_internal.h"
4445
}
4546

‎Foundation/testsuite/src/AnyTest.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "Poco/Bugcheck.h"
3939
#include <vector>
4040

41+
GCC_DIAG_OFF(unused-but-set-variable)
4142
#if defined(_MSC_VER) && _MSC_VER < 1400
4243
#pragma warning(disable:4800)//forcing value to bool 'true' or 'false'
4344
#endif

‎Foundation/testsuite/src/ClassLoaderTest.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "Poco/Exception.h"
3939
#include "TestPlugin.h"
4040

41+
GCC_DIAG_OFF(unused-variable)
4142

4243
using Poco::ClassLoader;
4344
using Poco::Manifest;

‎Foundation/testsuite/src/ClassLoaderTest.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
#include "Poco/Foundation.h"
4040
#include "CppUnit/TestCase.h"
41-
41+
#pragma GCC diagnostic ignored "-Wunused-variable"
4242

4343
class ClassLoaderTest: public CppUnit::TestCase
4444
{

‎Foundation/testsuite/src/CoreTest.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <vector>
5252
#include <cstring>
5353

54+
GCC_DIAG_OFF(unused-variable)
5455

5556
using Poco::Bugcheck;
5657
using Poco::Exception;

‎Foundation/testsuite/src/DateTimeTest.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "Poco/Timespan.h"
3939
#include "Poco/Exception.h"
4040

41+
GCC_DIAG_OFF(unused-variable)
4142

4243
using Poco::Timestamp;
4344
using Poco::DateTime;

‎Foundation/testsuite/src/FileTest.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <fstream>
4242
#include <set>
4343

44+
GCC_DIAG_OFF(unused-variable)
4445

4546
using Poco::File;
4647
using Poco::TemporaryFile;

‎Foundation/testsuite/src/HashMapTest.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "Poco/Exception.h"
3838
#include <map>
3939

40+
GCC_DIAG_OFF(unused-variable)
4041

4142
using Poco::HashMap;
4243

0 commit comments

Comments
 (0)