]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/11962 (ICE in type_dependent_expression on omitted second operand to ?...
authorMark Mitchell <mark@codesourcery.com>
Wed, 22 Oct 2003 02:08:47 +0000 (02:08 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 22 Oct 2003 02:08:47 +0000 (02:08 +0000)
PR c++/11962
* typeck.c (build_x_conditional_expr): Handle missing middle
operands in templates.
* mangle.c (write_expression): Issue errors about attempts to
mangle a non-existant middle operator to the ?: operator.

PR c++/11962
* g++.dg/template/cond2.C: New test.

From-SVN: r72785

gcc/cp/ChangeLog
gcc/cp/mangle.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/cond2.C [new file with mode: 0644]

index df0297ae5b296d7063c0646e26e685c849f29378..ba2ee1a2acf5f8d278252357e37056f45073d1e5 100644 (file)
@@ -1,3 +1,11 @@
+2003-10-21  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/11962
+       * typeck.c (build_x_conditional_expr): Handle missing middle
+       operands in templates.
+       * mangle.c (write_expression): Issue errors about attempts to
+       mangle a non-existant middle operator to the ?: operator.
+
 2003-10-21  Robert Bowdidge   <bowdidge@apple.com>
        * decl.c (cp_finish_decl): Remove clause intended for asm directives 
           in struct or class fields: this code is never executed.
index c8b3a84dddedb3e648ff1bb1c0c6ba5e0d0dee59..15334f321e328d555b306cd5e3b9661c1c5594fa 100644 (file)
@@ -2041,7 +2041,21 @@ write_expression (tree expr)
 
        default:
          for (i = 0; i < TREE_CODE_LENGTH (code); ++i)
-           write_expression (TREE_OPERAND (expr, i));
+           {
+             tree operand = TREE_OPERAND (expr, i);
+             /* As a GNU expression, the middle operand of a
+                conditional may be omitted.  Since expression
+                manglings are supposed to represent the input token
+                stream, there's no good way to mangle such an
+                expression without extending the C++ ABI.  */
+             if (code == COND_EXPR && i == 1 && !operand)
+               {
+                 error ("omitted middle operand to `?:' operand "
+                        "cannot be mangled");
+                 continue;
+               }
+             write_expression (operand);
+           }
        }
     }
 }
index f21115120661c9cdd65fa2f72017571909fcfd77..e469a5ace7e5a7e3e764a312bd6e7862050a8710 100644 (file)
@@ -4284,11 +4284,13 @@ build_x_conditional_expr (tree ifexp, tree op1, tree op2)
         IFEXP is type-dependent, even though the eventual type of the
         expression doesn't dependent on IFEXP.  */
       if (type_dependent_expression_p (ifexp)
-         || type_dependent_expression_p (op1)
+         /* As a GNU extension, the middle operand may be omitted.  */
+         || (op1 && type_dependent_expression_p (op1))
          || type_dependent_expression_p (op2))
        return build_min_nt (COND_EXPR, ifexp, op1, op2);
       ifexp = build_non_dependent_expr (ifexp);
-      op1 = build_non_dependent_expr (op1);
+      if (op1)
+       op1 = build_non_dependent_expr (op1);
       op2 = build_non_dependent_expr (op2);
     }
 
index a4509ebb3e93952abeb72ab546ac69fff5a9821c..5153e07640098686e9cfeea9e67cd702b5014579 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-21  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/11962
+       * g++.dg/template/cond2.C: New test.
+
 2003-10-20  Joseph S. Myers  <jsm@polyomino.org.uk>
 
        * gcc.dg/builtins-28.c: New test.
diff --git a/gcc/testsuite/g++.dg/template/cond2.C b/gcc/testsuite/g++.dg/template/cond2.C
new file mode 100644 (file)
index 0000000..abb6ebb
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/11962
+// { dg-options "" }
+
+template<int X> class c;
+
+template<int X, int Y> int test(c<X ? : Y>&);
+
+void test(c<2>*c2) {
+       test<0, 2>(*c2); // { dg-error "omitted" }
+}
This page took 0.136928 seconds and 5 git commands to generate.