Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: "Metzger, Markus T" <markus.t.metzger@intel.com>,
	       Eli Zaretskii <eliz@gnu.org>
Cc: "brobecker@adacore.com" <brobecker@adacore.com>,
	       "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	       "Jan Kratochvil (jan.kratochvil@redhat.com)"
	<jan.kratochvil@redhat.com>,
	       Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH] Enable C++11 starting with gcc 4.8 (was: Re: [PATCH 1/3] Introduce gdb::unique_ptr)
Date: Thu, 13 Oct 2016 00:38:00 -0000	[thread overview]
Message-ID: <97f51cf1-be35-1328-78e5-3642479e67fa@redhat.com> (raw)
In-Reply-To: <46f76e28-dda9-632b-2f76-81fdcbee63bf@redhat.com>

On 10/12/2016 11:28 AM, Pedro Alves wrote:
> On 10/12/2016 09:11 AM, Metzger, Markus T wrote:
> 
>> A simple and pragmatic solution would be a patch to add -std=c++11
>> to GDB's compiler options.  Pedro already mentioned it but I'm afraid it
>> got lost.
> 
> Looks like it, yes.  As I've explained, we can't do it on src/gdb/
> alone, because the CXX make variable is passed down from the top level,
> which would override whatever we set in gdb/'s configure/Makefile.
> 
> I want to give it a try, though.  It just requires time and getting
> the patch into gcc and merged back.  I don't think that should hold
> back the proposed series (or pieces of it).
> 
> I wasn't originally meaning to unconditionally add -std=c++11 though,
> but instead to only add it if the compiler supports it, in order
> to conservatively still support C++03-only compilers.

OK, I spend a few hours tonight working on this.

I was thinking ahead that we'll like have other C++ libraries in
the top level that we'd be using (code shared with gcc, and also
gdbserver moving to top level, maybe parts split to libraries, etc.).

And I was mistakenly under the impression that all subdirs would have to be
built with the same C++ dialect, given the C++11 ABI change.  I.e.,
use the same dialect throughout to avoid ABI conflicts.

So I first wrote a patch that had the top level configure source a
file in each subdir that would tell the top level the minimum and
maximum C++ dialect versions each subdir supported, and then the
top level could compute the dialect to set CXX to.

But,
 https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
explains how mixing dialects is not really a problem.

So I was over complicating.

However, the issue with CXX being passed by the top level overriding
whatever gdb's configure/Makefile decide to set CXX to is
real though.  But I solved it in a different way, all within gdb/

Instead of having configure append -std=xxx to CXX, simply set a
separate CXX_DIALECT variable, and tweak the Makefile to use
"$CXX CXX_DIALECT" to compile/link.

In order to detect whether the compiler supports C++11 (i.e.,
if we're using gcc 4.8 or later, or a clang that supports C++11,
etc.), I'm reusing a macro from the GNU Autoconf Archive, at:

 http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html

To recap:

> Conceptually, the gdb::unique_ptr patch (this thread) does:
> 
> #if HAVE_STD_UNIQUE_PTR
> 
> // just use it
> 
> #else
> 
> // write replacement
> 
> #endif
> 
> The replacement is fully functional.
> 
> If I push the patch in now, HAVE_STD_UNIQUE_PTR will only be true
> when compiling GDB with GCC >= 6.x, because G++ 6.1 targets G++14
> by default, which is a superset of C++11.  The replacement
> works with all other GCCs.  It'd be possible to make
> HAVE_STD_UNIQUE_PTR be true with GCC >= 4.x too, but nobody wrote
> that patch yet.

So I wrote that patch now.

IOW, the idea is that gdb::unique_ptr maps to C++11
std::unique_ptr iff C++11 is available and to a replacement
otherwise.  The C++03 replacement works just as well, however
the C++11 version catches more bugs at compile time.

Full C++11 support is available starting with gcc 4.8, however
only gcc 6.1 switched to default to C++11 (C++14, actually).
So for gcc 4.8 till gcc 6.1, we need to explicitly pass -std=gnu++11
to the compiler.  That's what the patch I wrote tonight does.
I'll send it as reply to this email.  Two patches actually.

> But if we agree to go full-on C++11, then I'll be more than
> happy to make gdb's configure error out on non-C++11 compilers.

The patches add this to configure:

 AX_CXX_COMPILE_STDCXX(11, , optional)

"optional" means that not having a C++11 compiler is OK.
IOW, "try to enable C++11 iff possible".

If we decide to _require_ C++11 (i.e., drop support for C++03-only), then
it's a simple matter of changing that to:

 AX_CXX_COMPILE_STDCXX(11, , mandatory)

Thanks,
Pedro Alves


  parent reply	other threads:[~2016-10-13  0:38 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10 16:46 [PATCH 0/3] More cleanup elimination / gdb::unique_ptr Pedro Alves
2016-10-10 16:46 ` [PATCH 1/3] Introduce gdb::unique_ptr Pedro Alves
2016-10-10 17:49   ` Simon Marchi
2016-10-10 18:03     ` Pedro Alves
2016-10-11  6:48   ` Metzger, Markus T
2016-10-11 10:23     ` Pedro Alves
2016-10-11 10:53       ` Andreas Schwab
2016-10-11 11:17       ` Metzger, Markus T
2016-10-11 11:43         ` Pedro Alves
2016-10-11 13:58           ` Yao Qi
2016-10-11 14:05           ` Trevor Saunders
2016-10-11 12:16       ` Joel Brobecker
2016-10-11 13:46         ` Pedro Alves
2016-10-11 14:47           ` Joel Brobecker
2016-10-11 15:17             ` Eli Zaretskii
2016-10-11 16:24               ` Pedro Alves
2016-10-11 16:58                 ` Eli Zaretskii
2016-10-11 17:41                   ` Pedro Alves
2016-10-11 18:37                     ` Eli Zaretskii
2016-10-11 19:19                       ` Pedro Alves
2016-10-11 20:47                         ` Eli Zaretskii
2016-10-11 21:32                           ` Pedro Alves
2016-10-12  6:34                             ` Eli Zaretskii
2016-10-12  8:11                               ` Metzger, Markus T
2016-10-12  9:31                                 ` Eli Zaretskii
2016-10-12 10:12                                   ` Pedro Alves
2016-10-12 11:05                                     ` Eli Zaretskii
2016-10-12 11:25                                       ` Pedro Alves
2016-10-12 11:45                                         ` Eli Zaretskii
2016-10-13 12:12                                           ` Pedro Alves
2016-10-12 10:28                                 ` Pedro Alves
2016-10-12 11:07                                   ` Eli Zaretskii
2016-10-12 11:19                                     ` Pedro Alves
2016-10-12 11:41                                       ` Eli Zaretskii
2016-10-12 11:55                                         ` Pedro Alves
2016-10-13  0:38                                   ` Pedro Alves [this message]
2016-10-13  0:45                                     ` [PATCH 1/2] gdb: Import AX_CXX_COMPILE_STDCXX from the GNU Autoconf Archive Pedro Alves
2016-10-13  0:45                                     ` [PATCH 2/2] gdb: Enable C++11 if available Pedro Alves
2016-10-12  9:37                               ` [PATCH 1/3] Introduce gdb::unique_ptr Pedro Alves
2016-10-12 10:51                                 ` Eli Zaretskii
2016-10-12 11:15                                   ` Pedro Alves
2016-10-12 11:40                                     ` Eli Zaretskii
2016-10-12 11:45                                   ` Jan Kratochvil
2016-10-12 11:56                                     ` Luis Machado
2016-10-12 12:03                                     ` Eli Zaretskii
2016-10-13  9:07                                       ` Jan Kratochvil
2016-10-13 10:07                                         ` Eli Zaretskii
2016-10-13 10:27                                           ` Pedro Alves
2016-10-13 13:22                                             ` Eli Zaretskii
2016-10-13 13:36                                               ` Pedro Alves
2016-10-13 13:59                                                 ` Eli Zaretskii
2016-10-13 14:04                                                   ` Pedro Alves
2016-10-13 15:06                                                     ` Joel Brobecker
2016-10-13 10:46                                           ` Jan Kratochvil
2016-10-13 11:15                                             ` Pedro Alves
2016-10-13 13:28                                             ` Eli Zaretskii
2016-10-13 13:42                                               ` Pedro Alves
2016-10-13 14:07                                                 ` Eli Zaretskii
2016-10-11 19:23                       ` Simon Marchi
2016-10-11 20:54                         ` Eli Zaretskii
2016-10-11 21:28                           ` Simon Marchi
2016-10-12  6:23                             ` Eli Zaretskii
2016-10-11 21:16                         ` Jan Kratochvil
2016-10-11 17:15                 ` Luis Machado
2016-10-11 18:21                   ` Pedro Alves
2016-10-10 16:46 ` [PATCH 3/3] 'struct parse_expression *' -> gdb::unique_ptr<expression> Pedro Alves
2016-10-10 16:58 ` [PATCH 0/3] More cleanup elimination / gdb::unique_ptr Pedro Alves
2016-10-16  7:05   ` Tom Tromey
2016-10-17 13:57     ` Pedro Alves
2016-10-17 14:07       ` Tom Tromey
2016-10-17 14:59         ` Pedro Alves
2016-10-20 13:46   ` Pedro Alves

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=97f51cf1-be35-1328-78e5-3642479e67fa@redhat.com \
    --to=palves@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=markus.t.metzger@intel.com \
    --cc=simon.marchi@ericsson.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