diff options
| author | Nicolai Stange <nicstange@gmail.com> | 2016-02-01 03:45:27 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-03-31 02:27:12 +0200 |
| commit | b59499db2f1dad0d18e0a6c43d381ab1b2047ee0 (patch) | |
| tree | d804be51591ce8e7011f57e9c9a6e358fd08d6b7 /validation | |
| parent | 56eeb88715772b14d7e2b93c41d67a35d7e6d0f8 (diff) | |
| download | sparse-dev-b59499db2f1dad0d18e0a6c43d381ab1b2047ee0.tar.gz | |
constexpr: support compound literals as address constants
Toplevel compound literals have got static storage duration
[6.5.2.5(6)].
This implies that
1. their addresses are address constants [6.6(9)] and
2. their initializers must contain constant expressions only
[6.5.2.5(3), 6.7.8(4)] .
Flag the anonymous symbol created at expression parsing time as having
static storage duration if the compound literal occurs at top level
scope.
Flag the whole expression as being an address constant at evaluation
time if its corresponding anonymous symbol had been previously marked
as having static storage duration.
Signed-off-by: Nicolai Stange <nicstange@gmail.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/constexpr-compound-literal.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/validation/constexpr-compound-literal.c b/validation/constexpr-compound-literal.c new file mode 100644 index 00000000..d7f21ad7 --- /dev/null +++ b/validation/constexpr-compound-literal.c @@ -0,0 +1,19 @@ +static int *a = &(int){ 1 }; // OK +static int *b = &(int){ *a }; // KO + +static void foo(void) +{ + int *b = &(int){ 1 }; // OK + int *c = &(int){ *a }; // OK + static int *d = &(int){ 1 }; // KO +} + +/* + * check-name: compound literal address constness verification + * check-command: sparse -Wconstexpr-not-const $file + * + * check-error-start +constexpr-compound-literal.c:2:25: warning: non-constant initializer for static object +constexpr-compound-literal.c:8:27: warning: non-constant initializer for static object + * check-error-end + */ |
