aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorNicolai Stange <nicstange@gmail.com>2016-02-01 03:34:34 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-03-31 02:14:10 +0200
commitc352b0d872b5c393d3ef1eb3053c19c298bcc82e (patch)
tree780adf6952189f8dbf5d3fbdce2e0b0d2e5b4812 /validation
parentccd9e3b5c6ab48bc03b52014a48ea53d681aa704 (diff)
downloadsparse-dev-c352b0d872b5c393d3ef1eb3053c19c298bcc82e.tar.gz
constexpr: examine constness of conditionals at evaluation only
Move the whole calculation of conditional expressions' constness flags to the evaluation phase such that expressions like 0 ? __builtin_choose_expr(0, 0, 0) : 0 0 ? 0 : __builtin_choose_expr(0, 0, 0) can now be recognized as qualifying as integer constant expressions. 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-conditional.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/validation/constexpr-conditional.c b/validation/constexpr-conditional.c
new file mode 100644
index 00000000..a3331b3e
--- /dev/null
+++ b/validation/constexpr-conditional.c
@@ -0,0 +1,34 @@
+static int a[] = {
+ [0 ? : 0] = 0, // OK
+ [1 ? : 0] = 0, // OK
+ [0 ? 0 : 0] = 0, // OK
+ [1 ? 0 : 0] = 0, // OK
+ [0 ? 0 : __builtin_choose_expr(0, 0, 0)] = 0, // OK
+ [1 ? __builtin_choose_expr(0, 0, 0) : 0] = 0, // OK
+ [0 ? __builtin_choose_expr(0, 0, 0) : 0] = 0, // OK
+ [1 ? 1 : __builtin_choose_expr(0, 0, 0)] = 0, // OK
+ [__builtin_choose_expr(0, 0, 0) ? : 0] = 0, // OK
+ [__builtin_choose_expr(0, 0, 1) ? : 0] = 0, // OK
+ [0. ? : 0] = 0, // KO
+ [0 ? 0. : 0] = 0, // KO
+ [1 ? : 0.] = 0, // KO
+ [__builtin_choose_expr(0, 0., 0) ? : 0] = 0, // OK
+ [__builtin_choose_expr(0, 0, 0.) ? : 0] = 0, // KO
+ [0 ? __builtin_choose_expr(0, 0., 0) : 0] = 0, // OK
+ [0 ? __builtin_choose_expr(0, 0, 0.) : 0] = 0, // KO
+ [1 ? 0 : __builtin_choose_expr(0, 0., 0)] = 0, // OK
+ [1 ? 0 : __builtin_choose_expr(0, 0, 0.)] = 0, // KO
+};
+
+/*
+ * check-name: Expression constness propagation in conditional expressions
+ *
+ * check-error-start
+constexpr-conditional.c:12:13: error: bad constant expression
+constexpr-conditional.c:13:19: error: bad constant expression
+constexpr-conditional.c:14:12: error: bad constant expression
+constexpr-conditional.c:16:42: error: bad constant expression
+constexpr-conditional.c:18:48: error: bad constant expression
+constexpr-conditional.c:20:14: error: bad constant expression
+ * check-error-end
+ */