[libcxx-commits] [PATCH] D150015: [libc++] Consistently enable __CORRECT_ISO_CPP_WCHAR_H_PROTO in mbstate.

Jordan Rupprecht via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 10 12:04:01 PDT 2023


rupprecht updated this revision to Diff 521068.
rupprecht marked an inline comment as done.
rupprecht added a comment.

- Add a comment explaining __CORRECT_ISO_CPP_WCHAR_H_PROTO, and uncomment the actual fix now that I'm done testing CI


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150015/new/

https://reviews.llvm.org/D150015

Files:
  libcxx/include/__mbstate_t.h
  libcxx/include/wchar.h
  libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp
  libcxx/test/std/strings/c.strings/cwchar_include_order2.compile.verify.cpp


Index: libcxx/test/std/strings/c.strings/cwchar_include_order2.compile.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/strings/c.strings/cwchar_include_order2.compile.verify.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <iosfwd>
+#include <cwchar>
+// 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}}
+}
Index: libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/strings/c.strings/cwchar_include_order1.compile.verify.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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}}
+}
Index: libcxx/include/wchar.h
===================================================================
--- libcxx/include/wchar.h
+++ libcxx/include/wchar.h
@@ -116,6 +116,8 @@
 #  pragma GCC system_header
 #endif
 
+// We define this here to support older versions of glibc <wchar.h> that do
+// not define this for clang.
 #ifdef __cplusplus
 #define __CORRECT_ISO_CPP_WCHAR_H_PROTO
 #endif
Index: libcxx/include/__mbstate_t.h
===================================================================
--- libcxx/include/__mbstate_t.h
+++ libcxx/include/__mbstate_t.h
@@ -27,6 +27,14 @@
 // This does not define std::mbstate_t -- this only brings in the declaration
 // in the global namespace.
 
+// We define this here to support older versions of glibc <wchar.h> that do
+// not define this for clang. This is also set in libc++'s <wchar.h> header,
+// and we need to do so here too to avoid a different function signature given
+// a different include order.
+#ifdef __cplusplus
+#  define __CORRECT_ISO_CPP_WCHAR_H_PROTO
+#endif
+
 #if __has_include(<bits/types/mbstate_t.h>)
 #   include <bits/types/mbstate_t.h> // works on most Unixes
 #elif __has_include(<sys/_types/_mbstate_t.h>)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150015.521068.patch
Type: text/x-patch
Size: 3295 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230510/14d10f75/attachment.bin>


More information about the libcxx-commits mailing list