llvm-project/libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp
Jordan Rupprecht 0ec57bf7b1 [libc++] Consistently enable __CORRECT_ISO_CPP_WCHAR_H_PROTO in mbstate.
In libc++'s `wchar.h`, before we forward to the system `wchar.h`, we set `__CORRECT_ISO_CPP_WCHAR_H_PROTO` to ensure it defines the correct signature (e.g. `extern "C++" const wchar_t *wmemchr` and not `extern wchar_t *wmemchr`). After D148542, there are cases where we include the system `wchar.h` from within `__mbstate_t.h` without setting that, and so we get a function type mismatch if we transitively include `wchar.h` through multiple headers in a modules-enabled build. Consistently setting it here resolves those build errors.

Alternative 1: we could put this in `__config` instead. I chose to put it here for a more limited scope.

Alternative 2: we could patch `wchar.h` itself to work correctly and remove references `__CORRECT_ISO_CPP_WCHAR_H_PROTO` from libc++ entirely. It does already set it, but with an additional condition that it is being built by GCC >= 4.4. Clang does pretend to be GCC via `__GNUC__` etc. which can be controlled via `-fgnuc-version` command line flags, but that might have other consequences.

Reviewed By: ldionne, #libc, MaskRay

Differential Revision: https://reviews.llvm.org/D150015
2023-05-10 15:43:38 -07:00

26 lines
772 B
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
//
//===----------------------------------------------------------------------===//
// <cwchar>
// XFAIL: no-wide-characters
// Tests that include ordering does not affect the definition of wcsstr.
// See: https://llvm.org/PR62638
// clang-format off
#include <cwchar>
#include <iosfwd>
// clang-format on
void func() {
wchar_t* v1;
const wchar_t* cv2 = L"/";
v1 = wcsstr(cv2, L"/"); // expected-error {{assigning to 'wchar_t *' from 'const wchar_t *' discards qualifiers}}
}