C++11

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
LGM-Doyle
Programmer
Posts: 219
Joined: Mon Feb 29, 2016 8:37 pm

C++11

#1 Post by LGM-Doyle »

I tried to search the forums for this topic, but C++11 is too short of a search term.

The question is.

Are we interested in starting to use C++11 features?

The more leading question is.

When will we be interested in using C++11 features?

I am bringing up this topic, mostly because I want to use the type inference of auto and the
automatic iteration of the new for loops.

Obviously, if the minimum versions of the compilers that we support do not support any features
of C++11 then this is a non-starter.

I think that the OSs/compilers that we are supporting are Apple/Clang(XCode), Linux/GCC, and Windows/MSVC.
I don't know what minimum versions of those compilers that we support.

The linked table shows C++ support in various compilers by version.
All C++11 features are supported by Clang 3.3, GCC 4.8.1 and MSVC 14.0.
Most features are supported by Clang 3.1, GCC 4.6, and MSVC 12.0.
Current compilers versions are Clang 3.8, GCC 5.3, and MSVC 14.0.

http://en.cppreference.com/w/cpp/compiler_support

C++11 features can simplify code for reading, improve performance and increase robustness.

The auto keyword, constexpr, ranged-for loop and initializer lists
all trivially improve readability and ease of writing.

Lambda expression can reduce verbosity in the code, depending on programmer use.

Rvalue references could improve performance
, depending on the extent of copy construction in the code.

Smart pointers, unique_ptr, shared_ptr and weak_ptr
are the new standard library versions of the same
from the Boost library.

This doesn't have to be an all or nothing change.
We could take individual features piecemeal and list
them on the compilation page as freeorion acceptable C++11 constructs.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: C++11

#2 Post by Geoff the Medio »

I think Vezzra has been unable to get a version of XCode that supports C++ to build FreeOrion, which has prevented any attempts to start using it.

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: C++11

#3 Post by Vezzra »

The problem is not that the version of Xcode I'm using (and the version of clang that comes with it) doesn't support C++11, but that my last attempts at building FO with C++11 enabled failed. Curiously enough, I've been able to do that already some time ago (two or three years, don't remember) on a try. We weren't considering doing that switch back then, and as doing it on OSX also means to give up compatibility with 10.6, I didn't pursue this further of course.

When the issue came up again (some time later), I tried again building with C++11 enabled, but failed. No one really pressed for the change, so again I dropped it. However, if the team wants to make the switch now, I can of course try again. Given the past experiences I expect that to be a considerable effort, so I'd have to prioritize this and put everything else on hold. And of course, I can't make any promises that I'll succeed, I'm not really an expert on these things. The C++ coding side has never been my strong suit, and unfortunately I'm the one and only Mac coder around here (AFAIK).

LGM-Doyle
Programmer
Posts: 219
Joined: Mon Feb 29, 2016 8:37 pm

Re: C++11

#4 Post by LGM-Doyle »

That surprises me. I thought Xcode/Clang C++11 support was solid.

Do you mean that freeorion could not be compiled on 10.6 or that it could not even
be compiled for 10.6 on another OSX machine when using C++11?

Are the issues with 10.6 still a problem, is it still in common use?
I don't know the distribution of OSX versions in the wild or how aggressively Apple upgrades them.

Were your problems getting C++11 to work with the compiler Clang or with project files Xcode?

If your problems were with Clang then I could try to cross-compile with Clang
by hacking the CMakefiles and fix the Clang issues in the code. Unlikely, but I'd try.

User avatar
adrian_broher
Programmer
Posts: 1156
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: C++11

#5 Post by adrian_broher »

Were your problems getting C++11 to work with the compiler Clang or with project files Xcode? […]
Unlikely, but I'd try.
It's probably the project setup.

No need to waste your time with testing the CMake build. I just build it and will push a new introduced issue in a few minutes.

Also when Vezzra talked about 'last time' we're talking about a time frame from around 2 years. Nobody cared enough for C++11 during that time to pester him for an updated project. Also we supported MSVC 2010 during that time which only has minimal C++11 support.
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: C++11

#6 Post by Vezzra »

LGM-Doyle wrote:That surprises me. I thought Xcode/Clang C++11 support was solid.
It is, as far as I can tell. Like I said, I already have been able to build FO with C++11 features enabled, I just failed to reproduce this success.
Do you mean that freeorion could not be compiled on 10.6 or that it could not even
be compiled for 10.6 on another OSX machine when using C++11?
The latter. I've already been on 10.8/10.10 when I tried to build with C++11, when I try to do that and set the min target OSX version to 10.6, I get an explicit error message stating that for C++11 the min target OSX version is 10.7.
Are the issues with 10.6 still a problem, is it still in common use?
No, that's not an issue anymore. Two, three years ago this was a different story, 10.6 wasn't that outdated at the time, and dropping support for it was something I tried to avoid if possible.
Were your problems getting C++11 to work with the compiler Clang or with project files Xcode?
I can't really tell that apart (I guess it's the latter), as I never build on the command line, invoking clang directly, I always build using Xcode. I guess that on my later, unsuccessful tries I must have failed to reproduce all the settings I apparently got right on my earlier, successful attempts.

The problem is that I don't really know what I'm doing. I'm not the one who set up the Xcode project, when I began contributing to FO (in late 2011) it was already there, but was somehow broken. Two guys were working on it to fix it, but were stuck. I then tried a few things, and, mostly by trial and error, got it working. There is probably a ton of legacy settings and other stuff you could remove, but as I said, not knowing what you're doing doesn't really help with that.

I've been maintaining the Xcode project ever since, but it's a bit of a fragile thing. It's more like keeping something running and hoping that nothing too serious breaks, because I might not be able to fix it.

Now, with all that in mind, just imagine me trying to make all the right adjustments to get FO building with C++11. I hope that this gives you a better idea of what the actual challenges of switching to C++11 on OSX are... ;)

LGM-Doyle
Programmer
Posts: 219
Joined: Mon Feb 29, 2016 8:37 pm

Re: C++11

#7 Post by LGM-Doyle »

Vezzra, I am being pushy with the C++11 transition because I am concerned that you will leave for vacation and C++11 adoption will also be pushed into the fall timeframe. I'm also hoping to be lucky and that you try the new PR I pushed and it just works, or the errors are obvious to someone here.

The release is the more important issue, so please ignore my request if you think it too much.

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: C++11

#8 Post by dbenage-cx »

Probably quickly earning an 'ignore anything he says' tag, but may be a conflict with using override to test, since it is already used in AIFramework.h and ServerFramework.h?
Any content posted should be considered licensed GNU GPL 2.0 and/or CC-BY-SA 3.0 as appropriate.

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: C++11

#9 Post by Vezzra »

LGM-Doyle wrote:Vezzra, I am being pushy with the C++11 transition because I am concerned that you will leave for vacation and C++11 adoption will also be pushed into the fall timeframe.
A valid concern. ;)
I'm also hoping to be lucky and that you try the new PR I pushed and it just works, or the errors are obvious to someone here.
You are lucky, and I did try, alas, it didn't just work. See my reply in the discussion thread of your PR. Doesn't look to bad though, there is only one issue I couldn't solve myself, and I'm hopeful that someone can help me out with that template/iterator/operator stuff that apparently is the problem here.
The release is the more important issue, so please ignore my request if you think it too much.
Trying to build and posting build errors is manageable. :)

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: C++11

#10 Post by Vezzra »

dbenage-cx wrote:Probably quickly earning an 'ignore anything he says' tag, but may be a conflict with using override to test, since it is already used in AIFramework.h and ServerFramework.h?
Ah yes, that's not really a problem so far. Just stupid me using the "override" directive in those locations without knowing that this is a C++11 feature. However, clang on OSX just gives a warning and ignores the statement, so I didn't bother to remove those uses of "override".

Post Reply