[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

warning: variable switch label

From: John W. Eaton
Subject: warning: variable switch label
Date: Sat, 1 Jul 2006 11:26:15 -0400

On  1-Jul-2006, Søren Hauberg wrote:

| Hi,
|   In 2.9.6 I get a warning that I really don't understand. If I have a
| switch statement such as this one:
| switch "a"
|   case {"a", "b"} disp("hello")
| endswitch
| I get this warning:
| warning: variable switch label
| I get that the problem is the {"a", "b"} part of the statement. But was
| is it that I'm being warned against?

The evaluator is trying to tell you that the expression

  {"a", "b"}

is not a constant.  It's not constant because the parser is not
converting that list expression to a constant cell object internally.
That's a minor bug that is easily fixed by the following patch.

The warning still makes some sense for things like this:

  octave:1> function y = f () y = "a"; end
  octave:2> switch "a"
  >   case {f, "b"} disp("hello")
  > endswitch
  warning: variable switch label

Here, there is no way to convert the expression

  {f, "b"}

to a constant value when the expression is parsed.

I copied this warning from GCC without thinking too much about it.
In C, I think a variable switch label is nonstandard.  For Octave,
there is no standard, so we can warn or not.  Should we?


2006-07-01  John W. Eaton  <address@hidden>

        * parse.y (finish_cell): Use finish_matrix to do constant folding.

Index: src/parse.y
RCS file: /cvs/octave/src/parse.y,v
retrieving revision 1.263
diff -u -u -r1.263 parse.y
--- src/parse.y 22 Jun 2006 00:57:28 -0000      1.263
+++ src/parse.y 1 Jul 2006 15:21:38 -0000
@@ -2789,9 +2789,7 @@
 static tree_expression *
 finish_cell (tree_cell *c)
-  // For now, this doesn't do anything.
-  return c;
+  return finish_matrix (c);
 static void

reply via email to

[Prev in Thread] Current Thread [Next in Thread]