[cfe-dev] Setting default dialect to C++11

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 2 09:42:16 PST 2017


On Thu, Mar 2, 2017 at 8:57 AM, Joerg Sonnenberger via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> > And I think that would commit us to keep C++03 forever, which is
> > untenable. Further, I think expecting the minimal maintenance required
> > to add "-std=c++03" if a project needs it is not unreasonable.
>
> Is it untenable? Why? POLA says to give a reasonable behavior and breaking
> existing code is not reasonable. Mandating what standard your code uses
> is actually a much saner choice. You are still ignoring my main point:
> there is no easy way to tell if a given code base needs -std=c++03.
> Older versions of SOCI for example worked perfectly well when compiled
> in C++11 mode, until you actually triggered an error. The error case
> then was far from pretty.
>

The way I see it, there are two categories of users that care about this
change:
1. C++ developers writing new build systems for new code
2. Users attempting to compile legacy C++ applications with legacy build
systems

Raising the default language version is a tradeoff that benefits the first
group and creates work for the second group. I claim that the first group
is larger. C++ as a language is growing, not shrinking. More C++ will be
written in the future than has been written in the past. We can't keep
piling on legacy forever. At some point we have to compromise backwards
compatibility to simplify things for users writing code *today*.

Raising the default improves things for the first group because they can
start to forget about the legacy of C++03/98 etc. People in this group have
already forgotten that pre-C++11 exists, except when they have to touch old
code. I'm in this group. I routinely run `clang -c` on user code samples,
forgetting to pass -std=c++11, and am surprised that we haven't raised the
version yet. All new C++ code is using C++11, so the majority of code I see
is C++11. For me and other such users, it would be nice if the compiler Did
The Right Thing by default.

The second group wants to build legacy code with build systems that are
poorly understood and undermaintained. Frankly, life is already hard for
these users. Clang regularly exploits UB in new and interesting ways that
break old code. This is just a cost of using a new compiler for a language
with undefined behavior. I assume that, as a NetBSD maintainer, Joerg
identifies with this group. I don't see the burden for these users as being
that great, these users can configure legacy projects with something like
'CXX=clang++ -std=c++03' to opt out of the change. Yes, it's work, but I
think the benefits for the larger group outweigh the costs.

I also don't expect that we will ever worry this much about raising the C++
language standard ever again. I predict that future language standards will
be significantly more backwards compatible. However, I'm also prepared to
be wrong, and maybe we'll be doing this song and dance again in 10 years.

---

So far it seems like Joerg is the only one against raising the default C++
language version. We should wait to gather more feedback, but if nobody
else comes forward to push back on this, I think it'll happen.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170302/5bc17584/attachment.html>


More information about the cfe-dev mailing list