# HG changeset patch # User Rik # Date 1588882447 25200 # Node ID 5e1f4060289a7ca2160bd9679a6079c5276e8afa # Parent 881649ab797812e8d97bede890cfa8ebb7eea1da Make 1-input form "warning (STATE)" use special ID "all" (bug #58296). Also, disallow using "all" ID with state "error". * error.cc (Fwarning): Detect case of 1-input "warning (STATE)" in input validation and execute same code as for 2-input form "warning (STATE, 'all')". Detect if STATE is "error" and immediately throw an error about incorrect usage. Remove code that previously handled this case. Update BIST test for new behavior. * randi.m: Update BIST tests for changes in behavior of warning(). diff -r 881649ab7978 -r 5e1f4060289a libinterp/corefcn/error.cc --- a/libinterp/corefcn/error.cc Thu May 07 11:14:44 2020 -0700 +++ b/libinterp/corefcn/error.cc Thu May 07 13:14:07 2020 -0700 @@ -1530,7 +1530,6 @@ octave_value curr_state = val.contents ("state"); // FIXME: this might be better with a dictionary object. - octave::tree_evaluator& tw = interp.get_evaluator (); octave_value curr_warning_states @@ -1584,39 +1583,28 @@ tw.set_auto_fcn_var (octave::stack_frame::SAVED_WARNING_STATES, m); - // Now ignore the "local" argument and continue to - // handle the current setting. + // Now ignore the "local" argument, + // and continue to handle the current setting. nargin--; } } - if (nargin >= 2 && arg2_lc == "all") + if ((nargin == 1 + && (arg1 == "on" || arg1 == "off" || arg1 == "error")) + || (nargin >= 2 && arg2_lc == "all")) { - // If "all" is explicitly given as ID. + // If "all" is given implicitly or explicitly as ID. + if (arg1 == "error") + error ("warning: cannot specify \"all\" warning ID with state \"error\""); octave_map tmp; - int is_error = (arg1 == "error"); - Cell id (1, 1 + 2*is_error); - Cell st (1, 1 + 2*is_error); + Cell id (1, 1); + Cell st (1, 1); id(0) = "all"; st(0) = arg1; - // Since internal Octave functions are not compatible, - // and "all"=="error" causes any "on" to throw an error, - // turning all warnings into errors should disable - // Octave:language-extension. - - if (is_error) - { - id(1) = "Octave:language-extension"; - st(1) = "off"; - - id(2) = "Octave:single-quote-string"; - st(2) = "off"; - } - tmp.assign ("identifier", id); tmp.assign ("state", st); @@ -1811,9 +1799,6 @@ } /* -%!test <*45753> -%! warning ("error"); -%! assert (! isempty (help ("warning"))); %!test <*51997> %! id = "Octave:logical-conversion"; @@ -1836,6 +1821,8 @@ %! idx = strcmp ({warnst.identifier}, "Octave:test-57290-ID"); %! assert (warnst(idx).state, "off"); +%!error warning ("error") + */ octave_value_list diff -r 881649ab7978 -r 5e1f4060289a scripts/general/randi.m --- a/scripts/general/randi.m Thu May 07 11:14:44 2020 -0700 +++ b/scripts/general/randi.m Thu May 07 13:14:07 2020 -0700 @@ -189,13 +189,9 @@ ## Test that no warning thrown if IMAX is exactly on the limits of the range %!function test_no_warning (func, varargin) -%! state = warning ("query"); -%! unwind_protect -%! warning ("error", "all"); -%! func (varargin{:}); -%! unwind_protect_cleanup -%! warning (state); -%! end_unwind_protect +%! lastwarn (""); +%! func (varargin{:}); +%! assert (lastwarn (), ""); %!endfunction %!test test_no_warning (@randi, max_int8, "int8"); %!test test_no_warning (@randi, max_uint8, "uint8");