Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Trevor Saunders <tbsaunde@tbsaunde.org>
To: Pedro Alves <palves@redhat.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
	tom@tromey.com, simon.marchi@polymtl.ca,
	gdb-patches@sourceware.org
Subject: Re: [RFA 09/22] Remove make_cleanup_restore_current_ui
Date: Thu, 13 Oct 2016 14:26:00 -0000	[thread overview]
Message-ID: <20161013143233.jh27bzboay6vt2za@ball> (raw)
In-Reply-To: <6f27db2e-4b88-b72a-5836-080c3583eb7f@redhat.com>

On Thu, Oct 13, 2016 at 11:16:26AM +0100, Pedro Alves wrote:
> On 10/13/2016 07:11 AM, Eli Zaretskii wrote:
> >> Cc: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
> >> From: Pedro Alves <palves@redhat.com>
> >> Date: Thu, 13 Oct 2016 02:28:44 +0100
> >>
> >> Yeah, sounds right.  I was trying get the gdb::unique_ptr in, in order
> >> to unblock the cases I suggested you use unique_ptr, but I'm a bit
> >> confused on what to do about it now...  I _think_ people are generally
> >> OK with it.  There was some opposition, but I'm not sure anymore
> >> whether it still exists.  C++11 is now on the table, but maybe a
> >> staged approach (enable C++11 while supporting C++03 too for a while,
> >> to catch issues) would make sense anyway.
> > 
> > I still think we shouldn't have workarounds for versions of the
> > standard older than what we want to support.
> 
> That is not what the patch does...  
> 
> #1 - Starting from the position that gdb wants to build with C++03
>      compilers.
> 
> #2 - The patch adds a new smart pointer type.  In C++03, you're pretty
>      much guaranteed to need to do that.  The one the standard gives you
>      is too limited.
> 
> #3 - (owning) smart pointers all look the same for most client code - they're
>      meant to look like raw pointers afterall - i.e., ptr->foo, and *ptr
>      works as expected, transparently.
> 
> #4 - where owning smart pointer APIs tend to differ is in code around pointee
>      ownership.
> 
>      I chose to model the API on std::unique_ptr (C++11).
>      There are advantages.
> 
> #5 - We could stop here.  Done.
> 
> #6 - But I went a step further, and made it so that if we have C++11
>      handy, then we can make use of the compiler to catch bugs at
>      compile time, all while keeping the nice API.
> 
> So again:
> 
> > I still think we shouldn't have workarounds for versions of the
> > standard older than what we want to support.
> 
> there's no workaround for versions older than what we want to support
> at all.  There's the code for the version that we had decided earlier
> that we wanted to support, plus extra API enforcement when built
> with a compiler that supports a version _newer_ than what we want
> to support.
> 
> 
> I'll give you more examples of why I think forbidding C++11 completely
> is short sighted.  C++11 has a nice feature where you can tell the compiler
> that some class is "final" (not possible to to inherit from that class).
> This allows the compiler to optimize the code better.
> 
> Another nice C++11 feature is that it's possible to mark class methods
> as overriding a virtual method in the base class.  This is quite handy,
> because with C++03, if you change the method's prototype in base class,
> you have to remember to update all users.  And without the "override" marker,
> the compiler won't help you find them at all.  The program builds, and then
> fails at run time.  Maybe only after release do you notice it.
> With the override marker, the compiler now errors out pointing at all
> the places you need to fix.  Bug found at compiler time.  Wonderful.
> 
> So if we have a C++11 compiler handy, why not make use of these
> features to help with development?  I don't see how it makes
> sense to not take advantage of compiler help if available.

And infact gdb already does the same exact sort of thing in the form of
the ATTRIBUTE_PRINTF macros.

> Here's GCC conditionally using these features if available as well:
> 
>   https://gcc.gnu.org/ml/jit/2016-q2/msg00000.html
> 
> And GCC still supports building with a C++03 compiler.  Just
> like GDB.  Tons of projects out there do the same thing.

as far as conditional compilation goes this seems a lot saner than  many
of the ifdefs in gcc, and probably the rest of the toolchain.  Its also
a lot easier to test than many of them.

> > IOW, if we decide to use
> > C++11, we should _require_ a compiler that supports it, and error out
> > if the configure test(s) regarding that fail.
> > 
> 
> So:
> 
> #1.1 - for people with new compilers, we'd go through C++11 std::unique_ptr
>        all the time.
> 
> #1.2 - people with older compilers would be out of luck.  tough.  get newer
>        compiler first.
> 
> Vs:
> 
> #2.1 - for people with new compilers, we'd go through std::unique_ptr all
>        the time.
> 
> #2.2 - for people with older compilers we go through the fallback
>        implementation.  gdb still works.
> 
> (I wasn't planning on starting the discussion on whether 1.2 is
> reasonable nowadays.  That happened because someone else brought it up.)
> 
> 
> So for people with newer compilers, the result is the same.
> (#1.1 == #1.2).  While I'm proposing a solution that gives us all the
> benefits (#2.1) while keeping support for older compilers
> for a little while longer (#2.2).
> 
> > Supporting more than one standard means we will have rarely used code
> > that is almost never tested, and that means maintenance burden 
> 
> That same argument could be applied to gnulib.  Or the many HAVE_FOO's
> in the code base.  We rely on gnulib's reimplementation of the whole
> printf family of functions if the compiler doesn't support it properly
> for example!

Claiming the C++98 code will be rarely tested is only true if very few
people try to compile gdb somewhere that doesn't have a C++11 compiler,
in which case yes we might as well drop support for C++98 compilers
because supporting them doesn't help anyone.  Basically you can't have
it both ways, either there are people who benefit from support for C++98
compilers, and so they'll test C++98 only code, or those people don't
exist, and you might as well require C++11.

> The sane way to make sure the fallback code still works is
> via autotesting with the buildbot.

and doing that is a whole lot easier than say testing if gdb works
without HAVE_PERSONALITY defined since testing the latter requires some
old kernel and probably glibc.

> > that means maintenance burden 
> 
> For whom?  _I'm_ willing to maintain this code.  It's not rocket
> science code.  And then users of the smart pointer don't really
> have to care.  Whether C++11 or C++03, you write the same code.
> You may miss a gdb::move call with C++03.  No big deal.  The fix
> is just to add a gdb::move call.
> 
> Several others have said they think this is a good idea.  I've even
> ran this idea through the libstdc++ maintainer in person at the Cauldron.
> Trevor said he wants to do this in gcc as well.
> 
> If redirecting to C++11 std::unique_ptr turns out to cause trouble, or
> I'm hit by a bus, then it's trivial to remove that redirection.  All it
> takes is remove a handful of lines of code guarded with
> #if __cplusplus >= 201103 to always go through the fallback implementation.
> 
> So there's no "point of no return here".
> 
> > which
> > threaten to undo at least some part of the benefits you aspire to
> > achieve by moving to C++ in general and to a new enough C++ standard
> > in particular.
> 
> I don't understand what this is trying to say.
> 
> I propose to move forward with my plan, and if it does cause
> trouble, then we drop the gdb::unique_ptr -> std::unique_ptr mapping.
> 
> It may happen, I don't know.  We will know if it will indeed cause
> trouble in practice if we try.

having delt with very similar smart pointers in other projects that
couldn't require C++11 I'll be suprised if it causes problems.

> And _in_ parallel, as a separate discussion, we can discuss dropping
> support for C++03 and going C++11 fully.  I think we could pull it
> off, but I wouldn't want to do it in a rush, and without an easy
> fallback plan available.  The patch I sent yesterday to make use
> of C++11 with gcc >= 4.8 would be the first step.  Then if that doesn't
> cause problems, we can tell the autoconf macro to require C++11
> with a single line change.  If _requiring_ C++11 causes significant
> trouble on people, and we want to go back to supporting older compilers,
> then it's easy to revert that, and go back to the unique_ptr C++03
> fallback implementation.  This is header-only template code, so we
> really can't tell if this will cause trouble for people without
> adding actual _uses_ of the smart pointer.

Yeah, I really don't see what the down side to adding the fall back, and
then deleting it in several weeks or months or whatever it ends up
taking to require C++11 is, and I don't see what the advantage of
rushing a switch to C++11 instead is.

Trev


  parent reply	other threads:[~2016-10-13 14:26 UTC|newest]

Thread overview: 121+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27  4:49 [RFA 00/22] More C++-ification Tom Tromey
2016-09-27  4:41 ` [RFA 15/22] Use std::string in macho_symfile_read_all_oso Tom Tromey
2016-10-09 17:28   ` Pedro Alves
2016-10-10 22:40     ` Tom Tromey
2016-10-10 22:46       ` Pedro Alves
2016-09-27  4:41 ` [RFA 07/22] Change scoped_minimal_symbol_reader to store objfile Tom Tromey
2016-09-29  9:19   ` Trevor Saunders
2016-09-30 21:41     ` Tom Tromey
2016-09-27  4:42 ` [RFA 16/22] Use std::vector in elf_read_minimal_symbols Tom Tromey
2016-10-09 17:30   ` Pedro Alves
2016-09-27  4:42 ` [RFA 19/22] Convert tid_range_parser to class Tom Tromey
2016-09-30  1:41   ` Pedro Alves
2016-09-30 14:52     ` Tom Tromey
     [not found]       ` <926126cb-b3c5-340b-ac1c-5bc14ca41bf9@redhat.com>
2016-10-04 19:24         ` Pedro Alves
2016-10-04 23:09           ` Pedro Alves
2016-10-05  2:16             ` Trevor Saunders
2016-10-12  2:12             ` Tom Tromey
2016-10-13  1:06               ` Pedro Alves
2016-09-27  4:43 ` [RFA 20/22] Initial conversion of dwarf_expr_ctx Tom Tromey
2016-10-09 17:40   ` Pedro Alves
2016-09-27  4:45 ` [RFA 21/22] Convert DWARF expr functions to methods Tom Tromey
2016-10-09 19:18   ` Pedro Alves
2016-09-27  4:47 ` [RFA 02/22] Use RAII to save and restore scalars Tom Tromey
2016-09-27 10:24   ` Trevor Saunders
2016-09-30  1:40     ` Pedro Alves
2016-09-30  9:22       ` Pedro Alves
2016-09-30 15:00       ` Tom Tromey
2016-09-30 23:50         ` Pedro Alves
2016-09-30 15:44       ` Tom Tromey
2016-09-30 23:51         ` Pedro Alves
2016-10-01  3:55           ` Tom Tromey
2016-10-01  4:23             ` Tom Tromey
2016-10-01 10:33               ` Pedro Alves
2016-10-02 17:11                 ` Tom Tromey
2016-10-05  0:06                   ` Pedro Alves
2016-10-12 22:36                     ` Tom Tromey
2016-09-27  4:47 ` [RFA 04/22] Use scoped_restore for current_ui Tom Tromey
2016-09-27  4:47 ` [RFA 05/22] Turn wchar iterator into a class Tom Tromey
2016-10-06  1:01   ` Pedro Alves
2016-09-27  4:47 ` [RFA 22/22] Convert dwarf_expr_context_funcs to methods Tom Tromey
2016-10-09 19:11   ` Pedro Alves
2016-10-10 18:31     ` Pedro Alves
2016-10-10 19:33       ` Pedro Alves
2016-09-27  4:48 ` [RFA 08/22] Record minimal symbols directly in reader Tom Tromey
2016-10-01  4:29   ` Simon Marchi
2016-10-06  1:12     ` Pedro Alves
2016-09-27  4:48 ` [RFA 03/22] Use scoped_restore for ui_file Tom Tromey
2016-10-01  4:28   ` Simon Marchi
2016-10-01  5:22     ` Tom Tromey
2016-10-01 11:47       ` Simon Marchi
2016-10-13 14:56         ` Tom Tromey
2016-09-27  4:48 ` [RFA 01/22] Change selttest.c to use use std::vector Tom Tromey
2016-09-27  8:50   ` Trevor Saunders
2016-09-27 16:44     ` Tom Tromey
2016-09-28 14:58       ` Trevor Saunders
2016-09-29  8:59         ` Tom Tromey
2016-10-06  0:18       ` Pedro Alves
2016-10-06  0:39       ` Pedro Alves
2016-09-30 14:43   ` Simon Marchi
2016-09-30 21:40     ` Tom Tromey
2016-10-06  0:45       ` Pedro Alves
2016-09-27  4:48 ` [RFA 09/22] Remove make_cleanup_restore_current_ui Tom Tromey
2016-09-29 11:55   ` Trevor Saunders
2016-10-01  3:47     ` Tom Tromey
2016-10-01  4:29   ` Simon Marchi
2016-10-06  2:53     ` Tom Tromey
2016-10-06  1:24   ` Pedro Alves
2016-10-06  2:52     ` Tom Tromey
2016-10-09  4:31   ` Simon Marchi
2016-10-09 15:10     ` Tom Tromey
2016-10-09 19:20       ` Pedro Alves
2016-10-12 22:43         ` Tom Tromey
2016-10-13  1:28           ` Pedro Alves
2016-10-13  6:11             ` Eli Zaretskii
2016-10-13 10:16               ` Pedro Alves
2016-10-13 13:53                 ` Eli Zaretskii
2016-10-13 14:26                   ` Pedro Alves
2016-10-13 14:46                     ` Eli Zaretskii
     [not found]                       ` <9d9dca17-56a6-6c0a-44bb-efc425f24d8d@redhat.com>
2016-10-13 15:19                         ` Eli Zaretskii
2016-10-13 15:43                           ` Pedro Alves
2016-10-13 15:48                             ` Pedro Alves
2016-10-17 23:43                             ` Go C++11? (was: Re: [RFA 09/22] Remove make_cleanup_restore_current_ui) Pedro Alves
2016-10-18  6:14                               ` Eli Zaretskii
2016-10-19 18:02                               ` Go C++11? Luis Machado
2016-10-19 22:34                                 ` Pedro Alves
2016-10-13 15:27                       ` [RFA 09/22] Remove make_cleanup_restore_current_ui Pedro Alves
2016-10-13 14:26                 ` Trevor Saunders [this message]
2016-09-27  4:50 ` [RFA 17/22] Remove make_cleanup_restore_current_uiout Tom Tromey
2016-09-29 14:35   ` Trevor Saunders
2016-09-29 15:23     ` Tom Tromey
2016-09-29 17:55       ` Simon Marchi
2016-09-29 20:34         ` Tom Tromey
2016-09-30  2:45       ` Pedro Alves
2016-09-30 23:48         ` Tom Tromey
2016-09-30 23:52           ` Pedro Alves
2016-09-27  4:51 ` [RFA 14/22] Replace two xmallocs with vector Tom Tromey
2016-10-09 17:20   ` Pedro Alves
2016-10-12 22:39     ` Tom Tromey
2016-10-13  1:17       ` Pedro Alves
2016-10-13  2:04         ` Tom Tromey
2016-10-13 15:15     ` Tom Tromey
2016-10-13 15:26       ` Trevor Saunders
2016-09-27  4:51 ` [RFA 18/22] Some cleanup removal in dwarf2loc.c Tom Tromey
2016-10-09 17:37   ` Pedro Alves
2016-09-27  4:51 ` [RFA 13/22] Remove unnecessary cleanup from stabsread.c Tom Tromey
2016-09-30 16:19   ` Tom Tromey
2016-10-09 17:07   ` Pedro Alves
2016-09-27  4:51 ` [RFA 12/22] Remove unnecessary null_cleanup Tom Tromey
2016-10-09 17:06   ` Pedro Alves
2016-09-27  4:52 ` [RFA 06/22] Introduce scoped_minimal_symbol_reader Tom Tromey
2016-10-06  1:10   ` Pedro Alves
2016-10-06 15:37     ` Tom Tromey
2016-10-10 23:06     ` Tom Tromey
2016-10-10 23:26       ` Pedro Alves
2016-09-27  4:52 ` [RFA 10/22] Remove some cleanups in MI Tom Tromey
2016-10-06  1:42   ` Pedro Alves
2016-09-27  8:32 ` [RFA 11/22] Change command stats reporting to use class Tom Tromey
2016-10-09 17:01   ` Pedro Alves
2016-10-11 17:31     ` Tom Tromey
     [not found] ` <e06fbe1ea266e078eaff6bdc98e48efa@simark.ca>
2016-10-08 16:42   ` [RFA 00/22] More C++-ification Pedro Alves
2016-10-09  2:09   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161013143233.jh27bzboay6vt2za@ball \
    --to=tbsaunde@tbsaunde.org \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=simon.marchi@polymtl.ca \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox