view libinterp/corefcn/panic.h @ 33261:ab68bff7b8b8

style fixes for panic_ functions * panic.h (panic_impossible, panic_if, panic_unless): If NDEBUG is defined, define away using "do { } while (0)" so that a semicolon is always required. Also allow panic_impossible to be defined away if NDEBUG is defined. * lo-error.h (liboctave_panic_impossible, liboctave_panic_if, liboctave_panic_unless): Likewise.
author John W. Eaton <jwe@octave.org>
date Thu, 28 Mar 2024 00:32:26 -0400
parents 55e1412aca35
children
line wrap: on
line source

////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// This file is part of Octave.
//
// Octave is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Octave is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Octave; see the file COPYING.  If not, see
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////

#if ! defined (octave_panic_h)
#define octave_panic_h 1

#include "octave-config.h"

#include <cstdarg>

OCTAVE_NORETURN
extern OCTINTERP_API void vpanic (const char *fmt, va_list args);

OCTAVE_FORMAT_PRINTF (1, 2)
OCTAVE_NORETURN
extern OCTINTERP_API void panic (const char *fmt, ...);

// To allow the __FILE__ and __LINE__ macros to work as expected, the
// panic_impossible, panic_if, and panic_unless symbols must be defined
// as macros.

#if defined (NDEBUG)

#  define panic_impossible() do { } while (0)

#  define panic_if(cond) do { } while (0)

#  define panic_unless(cond) do { } while (0)

#else

#  define panic_impossible()                                                            \
  ::panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)

#  define panic_if(cond) do { if (cond) panic_impossible (); } while (0)

#  define panic_unless(cond) panic_if (! (cond))

#endif

#endif