Re: CFT: snmalloc as libc malloc (the nullptr_t issue)

From: Mark Millard <marklmi_at_yahoo.com>
Date: Fri, 10 Feb 2023 20:53:18 UTC
On Feb 10, 2023, at 12:01, Mark Millard <marklmi@yahoo.com> wrote:

> Looks to me like FreeBSD's problem: there is a rule about <stddef.h>
> inclusion leading to a definition of nullptr_t that is not being
> followed. The details follow.
> 
> The complaint:
> 
> /usr/obj/data/src/hardenedbsd/amd64.amd64/tmp/usr/include/c++/v1/cstddef:50:9: error: no member named 'nullptr_t' in the global namespace
> using ::nullptr_t;
> 
> is reported against text in FreeBSD's usr/include/c++/v1/cstddef
> (so against the llvm15 integration).
> 
> cppreference.com <http://cppreference.com/> reports for nullptr_t :
> 
> . . .
> Defined in header <cstddef>
> using nullptr_t = decltype(nullptr);
> 
> Notes
> nullptr_t is available in the global namespace when <stddef.h> is included, even if it is not a part of C99~C17 (referenced by C++11~C++20).
> nullptr_t is also a part of C since C23.
> . . .
> 
> c++/v1/cstddef has, in part:
> 
> . . .
> #include <stddef.h>
> #include <version>
> 
> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
> #  pragma GCC system_header
> #endif
> 
> _LIBCPP_BEGIN_NAMESPACE_STD
> 
> using ::nullptr_t;
> . . .
> 
> But, in FreeBSD, <stddef.h> directly and indirectly does not lead to
> a nullptr_t definition as far as I could find.
> 

I missed the fact that there is another stddef.h:

/usr/include/c++/v1/stddef.h

that looks like:

// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#if defined(__need_ptrdiff_t) || defined(__need_size_t) || \
    defined(__need_wchar_t) || defined(__need_NULL) || defined(__need_wint_t)

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#  pragma GCC system_header
#endif

#include_next <stddef.h>

#elif !defined(_LIBCPP_STDDEF_H)
#define _LIBCPP_STDDEF_H

/*
    stddef.h synopsis

Macros:

    offsetof(type,member-designator)
    NULL

Types:

    ptrdiff_t
    size_t
    max_align_t // C++11
    nullptr_t

*/

#include <__config>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#  pragma GCC system_header
#endif

#include_next <stddef.h>

#ifdef __cplusplus
    typedef decltype(nullptr) nullptr_t;
#endif

#endif // _LIBCPP_STDDEF_H


So, another way of saying things is: this one seems to not be
in use but should be. Note the dependency on defined(__need_NULL)
for the initial #if .

===
Mark Millard
marklmi at yahoo.com