Hash :
df7978ac
Author :
Date :
2025-06-02T18:32:26
stddef-h: Fix compilation errors in C++ mode (regression 2025-05-27). * m4/stddef_h.m4 (gl_STDDEF_H): Set and substitute HAVE_C_UNREACHABLE. Don't test for unreachable in <stddef.h> in C++. Set GL_GENERATE_STDDEF_H to true always. * lib/stddef.in.h (gl_unreachable): Renamed from _gl_unreachable. Test HAVE_C_UNREACHABLE. (unreachable): Don't define in C++ mode. Don't define if HAVE_C_UNREACHABLE is 1. * modules/stddef-h (Makefile.am): Substitute HAVE_C_UNREACHABLE. * tests/test-stddef-h.c (test_unreachable_optimization, test_unreachable_noreturn): Don't define in C++ mode. (test_gl_unreachable_optimization, test_gl_unreachable_noreturn): New functions. * tests/test-stddef-h-c++3.cc (test_cxx_unreachable_1): Test gl_unreachable instead of unreachable. * lib/error.in.h (__gl_error_call1): Use gl_unreachable instead of unreachable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/* Test of <stddef.h> substitute in C++ mode.
Copyright (C) 2019-2025 Free Software Foundation, Inc.
This program 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.
This program 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 this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Define gl_unreachable. */
#include <stddef.h>
/* Define std::unreachable (in C++23 or newer). */
#include <utility>
void
test_cxx_unreachable_1 ()
{
if (2 < 1)
gl_unreachable ();
#if defined __cpp_lib_unreachable
if (3 < 1)
std::unreachable ();
#endif
}
#if defined __cpp_lib_unreachable
using std::unreachable;
void
test_cxx_unreachable_2 ()
{
if (3 < 1)
unreachable ();
}
#endif