[committed] libstdc++: Fix uses of non-reserved names in headers

2023-02-16 Thread Maciej Cencora via Gcc-patches
Hi,

instead of uglyfing all the libstdc++ code wouldn't it be simpler to
just ignore all non-reserved macro expansions (+ some special ones
like assert) inside system headers on compiler level?

Regards,
Maciej


Re: [committed] libstdc++: Fix uses of non-reserved names in headers

2023-02-16 Thread Jonathan Wakely via Gcc-patches
On Thu, 16 Feb 2023 at 11:45, Jakub Jelinek  wrote:
>
> On Thu, Feb 16, 2023 at 11:47:54AM +0100, Jakub Jelinek via Gcc-patches wrote:
> > On Thu, Feb 16, 2023 at 10:30:30AM +, Jonathan Wakely via Gcc-patches 
> > wrote:
> > > Tested powerpc64le-linux. Pushed to trunk.
> > >
> > > These should be backported too.
> > >
> > > -- >8 --
> > >
> > > The non-reserved names 'val' and 'dest' were being used in our headers
> > > but haven't been added to the 17_intro/names.cc test. That's because
> > > they are used by  and 
> > > respecitvely on glibc-based systems.
> >
> > So, can't we for such problematic names add hacks, like some directory
> > which the test adds as -isystem before the standard ones and contains
>
> Or do it the way you just did for PSTL, by including all the non-libstdc++
> headers used in libstdc++ headers before defining all the macros for the
> non-reserved names, hopefully the system headers use include guards and
> won't be included again.


Yes, I tried that last week, and it didn't work. There was a
diagnostic about __GLIBCXX__ being redefined, because of the {
dg-add-options no_pch } directive.

I can try again, or we can just use the existing solution of doing
#undef val #undef dest for glibc and/or linux targets, so that we
still test those names on other targets.



Re: [committed] libstdc++: Fix uses of non-reserved names in headers

2023-02-16 Thread Jonathan Wakely via Gcc-patches
On Thu, 16 Feb 2023 at 10:48, Jakub Jelinek  wrote:
>
> On Thu, Feb 16, 2023 at 10:30:30AM +, Jonathan Wakely via Gcc-patches 
> wrote:
> > Tested powerpc64le-linux. Pushed to trunk.
> >
> > These should be backported too.
> >
> > -- >8 --
> >
> > The non-reserved names 'val' and 'dest' were being used in our headers
> > but haven't been added to the 17_intro/names.cc test. That's because
> > they are used by  and 
> > respecitvely on glibc-based systems.
>
> So, can't we for such problematic names add hacks, like some directory
> which the test adds as -isystem before the standard ones and contains
> some header wrappers which temporarily
> #undef val
> #undef dest
> (or whatever other name), then
> #include_next ...
> and then define them again?
> Doesn't need to be for all targets of course, but just something to cover
> at least the most common ones.
>
> Or perhaps even do it differently, add 2 headers, one which defines
> all those #define whatever (, one that #undef whatever them all,
> and add wrappers in a -isystem directory for all non-gcc owned headers
> used by the libstdc++ headers, which would include this #undef header
> first and #define at the end.  That way we wouldn't test non-reserved
> names in say libc headers, just in libstdc++ headers.

We could, but it seems like a lot of work just for "val" and "dest",
when there are much simpler solutions :-)



Re: [committed] libstdc++: Fix uses of non-reserved names in headers

2023-02-16 Thread Jakub Jelinek via Gcc-patches
On Thu, Feb 16, 2023 at 11:47:54AM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Thu, Feb 16, 2023 at 10:30:30AM +, Jonathan Wakely via Gcc-patches 
> wrote:
> > Tested powerpc64le-linux. Pushed to trunk.
> > 
> > These should be backported too.
> > 
> > -- >8 --
> > 
> > The non-reserved names 'val' and 'dest' were being used in our headers
> > but haven't been added to the 17_intro/names.cc test. That's because
> > they are used by  and 
> > respecitvely on glibc-based systems.
> 
> So, can't we for such problematic names add hacks, like some directory
> which the test adds as -isystem before the standard ones and contains

Or do it the way you just did for PSTL, by including all the non-libstdc++
headers used in libstdc++ headers before defining all the macros for the
non-reserved names, hopefully the system headers use include guards and
won't be included again.

Jakub



Re: [committed] libstdc++: Fix uses of non-reserved names in headers

2023-02-16 Thread Jakub Jelinek via Gcc-patches
On Thu, Feb 16, 2023 at 10:30:30AM +, Jonathan Wakely via Gcc-patches wrote:
> Tested powerpc64le-linux. Pushed to trunk.
> 
> These should be backported too.
> 
> -- >8 --
> 
> The non-reserved names 'val' and 'dest' were being used in our headers
> but haven't been added to the 17_intro/names.cc test. That's because
> they are used by  and 
> respecitvely on glibc-based systems.

So, can't we for such problematic names add hacks, like some directory
which the test adds as -isystem before the standard ones and contains
some header wrappers which temporarily
#undef val
#undef dest
(or whatever other name), then
#include_next ...
and then define them again?
Doesn't need to be for all targets of course, but just something to cover
at least the most common ones.

Or perhaps even do it differently, add 2 headers, one which defines
all those #define whatever (, one that #undef whatever them all,
and add wrappers in a -isystem directory for all non-gcc owned headers
used by the libstdc++ headers, which would include this #undef header
first and #define at the end.  That way we wouldn't test non-reserved
names in say libc headers, just in libstdc++ headers.

What both of these break though is if libstdc++ headers try to use
__has_include etc. on them, because the added wrapper will mean they will
show as existing.

Jakub



[committed] libstdc++: Fix uses of non-reserved names in headers

2023-02-16 Thread Jonathan Wakely via Gcc-patches
Tested powerpc64le-linux. Pushed to trunk.

These should be backported too.

-- >8 --

The non-reserved names 'val' and 'dest' were being used in our headers
but haven't been added to the 17_intro/names.cc test. That's because
they are used by  and 
respecitvely on glibc-based systems.

libstdc++-v3/ChangeLog:

* include/bits/fs_ops.h (create_directory): Use reserved name
for parameter.
* include/bits/ranges_algo.h (__contains_subrange_fn):
Likewise.
* include/bits/regex_automaton.h (_State_base::_M_print):
Likewise.
* include/bits/regex_automaton.tcc(_State_base::_M_print):
Likewise.
* include/bits/regex_scanner.tcc(_Scanner::_M_print): Likewise.
* include/experimental/bits/fs_ops.h (create_directory):
Likewise.
* include/std/mutex (timed_mutex::_M_clocklock): Likewise.
(recursive_timed_mutex:_M_clocklock): Likewise.
* include/std/tuple (basic_common_reference): Likewise.
* libsupc++/cxxabi_init_exception.h
(__cxa_init_primary_exception): Likewise.
* testsuite/17_intro/names.cc: Add checks.
---
 libstdc++-v3/include/bits/fs_ops.h|  4 +-
 libstdc++-v3/include/bits/ranges_algo.h   |  6 +-
 libstdc++-v3/include/bits/regex_automaton.h   |  2 +-
 libstdc++-v3/include/bits/regex_automaton.tcc | 18 +++---
 libstdc++-v3/include/bits/regex_scanner.tcc   | 60 +--
 .../include/experimental/bits/fs_ops.h|  4 +-
 libstdc++-v3/include/std/mutex|  8 +--
 libstdc++-v3/include/std/tuple|  8 +--
 .../libsupc++/cxxabi_init_exception.h |  5 +-
 libstdc++-v3/testsuite/17_intro/names.cc  | 21 ++-
 10 files changed, 77 insertions(+), 59 deletions(-)

diff --git a/libstdc++-v3/include/bits/fs_ops.h 
b/libstdc++-v3/include/bits/fs_ops.h
index 74b8ad50210..e0b87c9fa00 100644
--- a/libstdc++-v3/include/bits/fs_ops.h
+++ b/libstdc++-v3/include/bits/fs_ops.h
@@ -90,8 +90,8 @@ namespace filesystem
   bool create_directory(const path& __p);
   bool create_directory(const path& __p, error_code& __ec) noexcept;
 
-  bool create_directory(const path& __p, const path& attributes);
-  bool create_directory(const path& __p, const path& attributes,
+  bool create_directory(const path& __p, const path& __attributes);
+  bool create_directory(const path& __p, const path& __attributes,
error_code& __ec) noexcept;
 
   void create_directory_symlink(const path& __to, const path& __new_symlink);
diff --git a/libstdc++-v3/include/bits/ranges_algo.h 
b/libstdc++-v3/include/bits/ranges_algo.h
index 1685e1d85bb..5d039bd1cd4 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -3490,11 +3490,11 @@ namespace ranges
 template _Sent1,
 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
 typename _Pred = ranges::equal_to,
-typename Proj1 = identity, typename Proj2 = identity>
-  requires indirectly_comparable<_Iter1, _Iter2, _Pred, Proj1, Proj2>
+typename _Proj1 = identity, typename _Proj2 = identity>
+  requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
   constexpr bool
   operator()(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 
__last2,
-_Pred __pred = {}, Proj1 __proj1 = {}, Proj2 __proj2 = {}) 
const
+_Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) 
const
   {
return __first2 == __last2
  || !ranges::search(__first1, __last1, __first2, __last2,
diff --git a/libstdc++-v3/include/bits/regex_automaton.h 
b/libstdc++-v3/include/bits/regex_automaton.h
index c2e4b512ed5..ef336d5883b 100644
--- a/libstdc++-v3/include/bits/regex_automaton.h
+++ b/libstdc++-v3/include/bits/regex_automaton.h
@@ -110,7 +110,7 @@ namespace __detail
 
 #ifdef _GLIBCXX_DEBUG
 std::ostream&
-_M_print(std::ostream& ostr) const;
+_M_print(std::ostream& __ostr) const;
 
 // Prints graphviz dot commands for state.
 std::ostream&
diff --git a/libstdc++-v3/include/bits/regex_automaton.tcc 
b/libstdc++-v3/include/bits/regex_automaton.tcc
index 546605da31f..f25f7b33263 100644
--- a/libstdc++-v3/include/bits/regex_automaton.tcc
+++ b/libstdc++-v3/include/bits/regex_automaton.tcc
@@ -36,34 +36,34 @@ namespace __detail
 {
 #ifdef _GLIBCXX_DEBUG
   inline std::ostream&
-  _State_base::_M_print(std::ostream& ostr) const
+  _State_base::_M_print(std::ostream& __ostr) const
   {
 switch (_M_opcode)
 {
   case _S_opcode_alternative:
   case _S_opcode_repeat:
-   ostr << "alt next=" << _M_next << " alt=" << _M_alt;
+   __ostr << "alt next=" << _M_next << " alt=" << _M_alt;
break;
   case _S_opcode_subexpr_begin:
-   ostr << "subexpr begin next=" << _M_next << " index=" << _M_subexpr;
+   __ostr << "subexpr begin next=" << _M_next << " index=" << _M_subexpr;
break;