[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
nullptr in C++ mode on macOS
From: |
Bruno Haible |
Subject: |
nullptr in C++ mode on macOS |
Date: |
Thu, 09 Feb 2023 20:31:04 +0100 |
On macOS 12.5 (machine: gcc104.fsffrance.org), the test-nullptr-c++.cc fails
to compile:
-----------------------------------------------------------------------------
Making check in .
c++ -DHAVE_CONFIG_H -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1
-DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib
-I../../gltests/../gllib -I/Users/haible/include -Wall -Wno-error -g -O2 -MT
test-nullptr-c++.o -MD -MP -MF .deps/test-nullptr-c++.Tpo -c -o
test-nullptr-c++.o ../../gltests/test-nullptr-c++.cc
../../gltests/test-nullptr-c++.cc:56:27: error: cannot pass object of non-POD
type 'std::nullptr_t' through variadic function; call will abort at runtime
[-Wnon-pod-varargs]
varargs_callee ("type", nullptr, "foo", nullptr);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__nullptr:48:17:
note: expanded from macro 'nullptr'
#define nullptr _VSTD::__get_nullptr_t()
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:858:15:
note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
^
../../gltests/test-nullptr-c++.cc:56:43: error: cannot pass object of non-POD
type 'std::nullptr_t' through variadic function; call will abort at runtime
[-Wnon-pod-varargs]
varargs_callee ("type", nullptr, "foo", nullptr);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__nullptr:48:17:
note: expanded from macro 'nullptr'
#define nullptr _VSTD::__get_nullptr_t()
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:858:15:
note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
^
2 errors generated.
make[3]: *** [test-nullptr-c++.o] Error 1
-----------------------------------------------------------------------------
What's happening? configure found out that
checking for C nullptr... no
checking for C++ nullptr... no
and accordingly, config.h contains
/* #undef HAVE_CXX_NULLPTR */
/* #undef HAVE_C_NULLPTR */
Here, nullptr is not defined as a keyword (as it should, cf.
https://en.cppreference.com/w/cpp/keyword/nullptr), but rather as a macro,
and only after some header file such as <stddef.h> has been included.
Our test "checking for C++ nullptr... no" found it out correctly.
But test-nullptr-c++.cc includes <iostream>, <vector>, etc. and these have
the effect of pulling a definition of nullptr_t and
#define nullptr _VSTD::__get_nullptr_t()
and this one does not work in varargs context.
So, we've now gone a full circle:
* nullptr and nullptr_t were introduced in C++, to resolve a problem with
overloading and a problem with varargs.
* The definition in this compiler solves the problem with overloading,
but is unusable with varargs.
* If we '#define nullptr __null' again after including the header files,
it will be usable with varargs, but will
- violate the requirement that nullptr is an instance of nullptr_t,
- and thus open up problems with overloading again.
I don't know how to proceed here. C++ is such a waste of time!!
Bruno
- nullptr in C++ mode on macOS,
Bruno Haible <=