improve trinary operator semantics
authorMatthias Braun <matze@braunis.de>
Sat, 29 Dec 2007 14:27:34 +0000 (14:27 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 29 Dec 2007 14:27:34 +0000 (14:27 +0000)
[r18832]

parser.c
parsetest/cp_error018.c

index e16f4d9..faf702c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -4193,8 +4193,15 @@ static expression_t *parse_conditional_expression(unsigned precedence,
                        && pointers_compatible(true_type, false_type)) {
                /* ok */
                result_type = true_type;
+       } else if (is_type_pointer(true_type)
+                       && is_null_pointer_constant(false_expression)) {
+               result_type = true_type;
+       } else if (is_type_pointer(false_type)
+                       && is_null_pointer_constant(true_expression)) {
+               result_type = false_type;
        } else {
-               /* TODO */
+               /* TODO: one pointer to void*, other some pointer */
+
                if (is_type_valid(true_type) && is_type_valid(false_type)) {
                        type_error_incompatible("while parsing conditional",
                                                expression->base.source_position, true_type,
index e0db872..c4ee5d6 100644 (file)
@@ -2,10 +2,17 @@ int puts(const char *msg);
 
 int main(int argc, char **argv)
 {
-       char *arg = argc > 1 ? argv[1] : 0;
+       void *nu = 0;
+       char *arg1 = argc > 1 ? argv[1] : 0;
+       char *arg2 = argc <= 1 ? 0 : argv[1];
+       char *arg3 = argc > 1 ? argv[1] : nu;
+       char *arg4 = argc <= 1 ? nu : argv[1];
 
-       if(arg != 0) {
-               puts(arg);
+       if(arg1 != 0) {
+               puts(arg1);
+               puts(arg2);
+               puts(arg3);
+               puts(arg4);
        }
 
        return 0;