[libcxx-commits] [PATCH] D147356: Fixing conflicting macro definitions between curses.h and std::filesystem.

Nicole Rabjohn via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 31 13:37:49 PDT 2023


nicolerabjohn created this revision.
nicolerabjohn added a reviewer: daltenty.
Herald added a project: All.
nicolerabjohn requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

POSIX allows certain macros to exist with generic names (i.e. refresh(), move(), and erase()) to exist in `curses.h` which conflict with functions found in std::filesystem. This patch undefs the macros in question and replaces them with inline functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147356

Files:
  libcxx/include/__undef_macros
  libcxx/test/libcxx/vendor/ibm/curses_macro_conflict.pass.cpp


Index: libcxx/test/libcxx/vendor/ibm/curses_macro_conflict.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/vendor/ibm/curses_macro_conflict.pass.cpp
@@ -0,0 +1,14 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: target={{powerpc.*-ibm-aix.*}}
+
+#include "curses.h"
+#include <filesystem>
+
+int main() { return 0; }
Index: libcxx/include/__undef_macros
===================================================================
--- libcxx/include/__undef_macros
+++ libcxx/include/__undef_macros
@@ -14,3 +14,33 @@
 #ifdef max
 #  undef max
 #endif
+
+#ifdef refresh
+#  if defined(__STDC__) || !defined(_NO_PROTO)
+inline int refresh_impl() { return refresh(); }
+#  else
+inline extern int refresh_impl() { return refresh(); }
+#  endif
+#  undef refresh
+inline int refresh() { return refresh_impl(); }
+#endif
+
+#ifdef move
+#  if defined(__STDC__) || !defined(_NO_PROTO)
+inline int move_impl(int x, int y) { return move(x, y); }
+#  else
+inline extern int move_impl(int x, int y) { return move(x, y); }
+#  endif
+#  undef move
+inline int move(int x, int y) { return move_impl(x, y); }
+#endif
+
+#ifdef erase
+#  if defined(__STDC__) || !defined(_NO_PROTO)
+inline int erase_impl() { return erase(); }
+#  else
+inline extern int erase_impl() { return erase(); }
+#  endif
+#  undef erase
+inline int erase() { return erase_impl(); }
+#endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147356.510124.patch
Type: text/x-patch
Size: 1758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230331/52bc2b6d/attachment-0001.bin>


More information about the libcxx-commits mailing list