Skip to content

Commit 6b94dae

Browse files
author
mikee47
committed
Clang is unhelpful. Can we at least get code through parser?
1 parent e4765f9 commit 6b94dae

File tree

8 files changed

+161
-17
lines changed

8 files changed

+161
-17
lines changed

src/include/FlashString/Array.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
*/
5555
#define DEFINE_FSTR_ARRAY_LOCAL(name, ElementType, ...) \
5656
static DEFINE_FSTR_ARRAY_DATA(FSTR_DATA_NAME(name), ElementType, __VA_ARGS__); \
57-
static constexpr DEFINE_FSTR_REF_NAMED(name, FSTR::Array<ElementType>);
57+
static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, FSTR::Array<ElementType>);
5858

5959
/**
6060
* @brief Define an Array data structure
@@ -63,9 +63,9 @@
6363
* @param ... List of ElementType items
6464
*/
6565
#define DEFINE_FSTR_ARRAY_DATA(name, ElementType, ...) \
66-
constexpr const struct { \
66+
FSTR_CONSTEXPR const struct { \
6767
FSTR::ObjectBase object; \
68-
ElementType data[sizeof((const ElementType[]){__VA_ARGS__}) / sizeof(ElementType)]; \
68+
ElementType data[FSTR_VA_NARGS(ElementType, __VA_ARGS__)]; \
6969
} FSTR_PACKED FSTR_ALIGNED name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \
7070
FSTR_CHECK_STRUCT(name);
7171

src/include/FlashString/Map.hpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
*/
5959
#define DEFINE_FSTR_MAP_LOCAL(name, KeyType, ContentType, ...) \
6060
static DEFINE_FSTR_MAP_DATA(FSTR_DATA_NAME(name), KeyType, ContentType, __VA_ARGS__); \
61-
static constexpr DEFINE_FSTR_REF_NAMED(name, DECL((FSTR::Map<KeyType, ContentType>)));
61+
static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, DECL((FSTR::Map<KeyType, ContentType>)));
6262

6363
/**
6464
* @brief Define a Map Object with global reference, specifying the number of elements
@@ -77,7 +77,7 @@
7777
*/
7878
#define DEFINE_FSTR_MAP_SIZED_LOCAL(name, KeyType, ContentType, size, ...) \
7979
static DEFINE_FSTR_MAP_DATA_SIZED(FSTR_DATA_NAME(name), KeyType, ContentType, size, __VA_ARGS__); \
80-
static constexpr DEFINE_FSTR_REF_NAMED(name, DECL((FSTR::Map<KeyType, ContentType>)));
80+
static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, DECL((FSTR::Map<KeyType, ContentType>)));
8181

8282
/**
8383
* @brief Define a Map data structure
@@ -89,9 +89,7 @@
8989
*/
9090
#define DEFINE_FSTR_MAP_DATA(name, KeyType, ContentType, ...) \
9191
DEFINE_FSTR_MAP_DATA_SIZED(name, KeyType, ContentType, \
92-
(sizeof((const FSTR::MapPair<KeyType, ContentType>[]){__VA_ARGS__}) / \
93-
sizeof(FSTR::MapPair<KeyType, ContentType>)), \
94-
__VA_ARGS__)
92+
FSTR_VA_NARGS(DECL((FSTR::MapPair<KeyType, ContentType>)), __VA_ARGS__), __VA_ARGS__)
9593

9694
/**
9795
* @brief Define a Map data structure, specifying the number of elements
@@ -102,7 +100,7 @@
102100
* @param ... List of MapPair definitions { key, &content }
103101
*/
104102
#define DEFINE_FSTR_MAP_DATA_SIZED(name, KeyType, ContentType, size, ...) \
105-
constexpr const struct { \
103+
FSTR_CONSTEXPR const struct { \
106104
FSTR::ObjectBase object; \
107105
FSTR::MapPair<KeyType, ContentType> data[size]; \
108106
} FSTR_PACKED FSTR_ALIGNED name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \

src/include/FlashString/Object.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@
8484
/**
8585
* @brief Check structure is POD-compliant and correctly aligned
8686
*/
87+
#ifdef __clang__
88+
#define FSTR_CHECK_STRUCT(name)
89+
#else
8790
#define FSTR_CHECK_STRUCT(name) \
8891
static_assert(std::is_pod<decltype(name)>::value, "FSTR structure not POD"); \
8992
static_assert(offsetof(decltype(name), data) == sizeof(uint32_t), "FSTR structure alignment error");
93+
#endif
9094

9195
/**
9296
* @brief Import an object from an external file with reference
@@ -107,7 +111,7 @@
107111
#define IMPORT_FSTR_OBJECT_LOCAL(name, ObjectType, file) \
108112
IMPORT_FSTR_DATA(FSTR_DATA_NAME(name), file) \
109113
extern "C" __attribute__((visibility("hidden"))) const FSTR::ObjectBase FSTR_DATA_NAME(name); \
110-
static constexpr DEFINE_FSTR_REF(name, ObjectType, FSTR_DATA_NAME(name));
114+
static FSTR_CONSTEXPR DEFINE_FSTR_REF(name, ObjectType, FSTR_DATA_NAME(name));
111115

112116
namespace FSTR
113117
{

src/include/FlashString/Stream.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Stream : public IDataSourceStream
5454
*/
5555
int available() override
5656
{
57-
return object.length() - readPos;
57+
return int(object.length() - readPos);
5858
}
5959

6060
uint16_t readMemoryBlock(char* data, int bufSize) override;

src/include/FlashString/String.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ typedef const __FlashStringHelper* flash_string_t;
8383
*/
8484
#define DEFINE_FSTR_LOCAL(name, str) \
8585
static DEFINE_FSTR_DATA(FSTR_DATA_NAME(name), str); \
86-
static constexpr DEFINE_FSTR_REF_NAMED(name, FSTR::String);
86+
static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, FSTR::String);
8787

8888
/**
8989
* @brief Define a FSTR::String data structure

src/include/FlashString/Vector.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
*/
5555
#define DEFINE_FSTR_VECTOR_LOCAL(name, ObjectType, ...) \
5656
static DEFINE_FSTR_VECTOR_DATA(FSTR_DATA_NAME(name), ObjectType, __VA_ARGS__); \
57-
static constexpr DEFINE_FSTR_REF_NAMED(name, FSTR::Vector<ObjectType>);
57+
static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, FSTR::Vector<ObjectType>);
5858

5959
/**
6060
* @brief Define a Vector Object with global reference, specifying the number of elements
@@ -73,7 +73,7 @@
7373
*/
7474
#define DEFINE_FSTR_VECTOR_SIZED_LOCAL(name, ObjectType, size, ...) \
7575
static DEFINE_FSTR_VECTOR_DATA_SIZED(FSTR_DATA_NAME(name), ObjectType, size, __VA_ARGS__); \
76-
static constexpr DEFINE_FSTR_REF_NAMED(name, FSTR::Vector<ObjectType>);
76+
static FSTR_CONSTEXPR DEFINE_FSTR_REF_NAMED(name, FSTR::Vector<ObjectType>);
7777

7878
/**
7979
* @brief Define a Vector data structure
@@ -83,7 +83,7 @@
8383
* @note Size will be calculated
8484
*/
8585
#define DEFINE_FSTR_VECTOR_DATA(name, ObjectType, ...) \
86-
DEFINE_FSTR_VECTOR_DATA_SIZED(name, ObjectType, sizeof((const void*[]){__VA_ARGS__}) / sizeof(void*), __VA_ARGS__)
86+
DEFINE_FSTR_VECTOR_DATA_SIZED(name, ObjectType, FSTR_VA_NARGS(ObjectType*, __VA_ARGS__), __VA_ARGS__)
8787

8888
/**
8989
* @brief Define a Vector data structure and specify the number of elements
@@ -94,10 +94,10 @@
9494
* @note Use in situations where the array size cannot be automatically calculated
9595
*/
9696
#define DEFINE_FSTR_VECTOR_DATA_SIZED(name, ObjectType, size, ...) \
97-
constexpr const struct { \
97+
FSTR_CONSTEXPR const struct { \
9898
FSTR::ObjectBase object; \
9999
const ObjectType* data[size]; \
100-
} name PROGMEM = {{sizeof(name.data)}, __VA_ARGS__}; \
100+
} name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \
101101
FSTR_CHECK_STRUCT(name);
102102

103103
namespace FSTR

0 commit comments

Comments
 (0)