[libc++] Fix incorrect usage of __STDC_HOSTED__

D56913 introduced the _LIBCPP_FREESTANDING macro and guarded its
definition by:

	#ifndef __STDC_HOSTED__
	#  define _LIBCPP_FREESTANDING
	#endif

However, __STDC_HOSTED__ is defined as 0 in freestanding implementations
instead of undefined, which means that _LIBCPP_FREESTANDING would never
get defined. This patch corrects the above as:

	#if __STDC_HOSTED__ == 0
	#  define _LIBCPP_FREESTANDING
	#endif

Differential Revision: https://reviews.llvm.org/D86055
This commit is contained in:
hyd-dev 2020-09-02 12:22:29 -04:00 committed by Louis Dionne
parent 5201b962e8
commit 44cc78da05
2 changed files with 22 additions and 1 deletions

View File

@ -38,7 +38,7 @@
# define _LIBCPP_ABI_VERSION 1
#endif
#ifndef __STDC_HOSTED__
#if __STDC_HOSTED__ == 0
# define _LIBCPP_FREESTANDING
#endif

View File

@ -0,0 +1,21 @@
// -*- 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
//
//===----------------------------------------------------------------------===//
// Test that _LIBCPP_FREESTANDING is not defined when -ffreestanding is not passed
// to the compiler but defined when -ffreestanding is passed to the compiler.
// RUN: %{cxx} %{flags} %{compile_flags} -fsyntax-only %s
// RUN: %{cxx} %{flags} %{compile_flags} -fsyntax-only -ffreestanding -DFREESTANDING %s
#include <__config>
#if defined(FREESTANDING) != defined(_LIBCPP_FREESTANDING)
#error _LIBCPP_FREESTANDING should be defined in freestanding mode and not \
defined in non-freestanding mode
#endif