[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 07:52:33 PDT 2023


rupprecht updated this revision to Diff 520991.
rupprecht added a comment.

- Add some tests, and temporarily comment out the fix to see if CI catches it.


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/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,18 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// Unexpectedly builds.
+#include <iosfwd>
+#include <cwchar>
+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,18 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// Fails, as expected.
+#include <iosfwd>
+#include <cwchar>
+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/__mbstate_t.h
===================================================================
--- libcxx/include/__mbstate_t.h
+++ libcxx/include/__mbstate_t.h
@@ -27,6 +27,13 @@
 // This does not define std::mbstate_t -- this only brings in the declaration
 // in the global namespace.
 
+// Consistently set this the same as in libc++'s <wchar.h> header to avoid
+// different function signatures.
+// Temporarily commenting this out to see if the added test catches anything in CI.
+// #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.520991.patch
Type: text/x-patch
Size: 2525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230510/058b65c1/attachment.bin>


More information about the libcxx-commits mailing list