Page 1 of 1

C++11 compilation sanity check

Posted: Tue Dec 24, 2013 5:33 pm
by petah
I apologize in advance since this is a compiler and not IDE issue (i.e. outside of CL's realm), but was wondering if anybody here was able to get any remotely advanced C++11 regex code (say std::regex_iterator) to build & link on Linux.

I tried gcc4.8 and built clang from trunk following Eran's wiki doc, but the linker barfs every time. Even http://en.cppreference.com/w/cpp/regex/ ... n_iterator doesn't work. Is it because g++ is lagging and clang uses libstd++'s headers or is there some obscure directive to link with another runtime lib? I tried LLVM's own libc++1 but can't tell if it gets linked in since it fails before any binary can be inspected with ldd.

Eran - do you by any chance have a snippet with a Clang compiler definition I could paste into ~/.codelite/config/build_settings.xml that's able to digest the smallest (non-wxWidget) regex sample?

thx again & sorry for the OT post.

-- p

Re: C++11 compilation sanity check

Posted: Thu Dec 26, 2013 5:01 pm
by petah
replying to my own post so I don't leave a hanging thread (this is Linux-only, everybody else "please disperse, nothing to see here").

Even though the gcc/g++ crew have claimed to be "C++11 complete" a while back, their fineprint is [*] doesn't include STL which depends on libstdc++. Practically that means you can merrily compile c++11 regexes, which may even link, but will barf at runtime. The behavior ranges from throwing an exception while evaluating the simplest regex to consistently returning empty strings no matter what you feed it.

The llvm/clang team implemented their own runtime library, called libc++, first for Mac but there are Linux ports... however I only came across very minimal examples, which work great with every c++11 feature I tested, but when trying to build real-world code (like wx's minimal sample) the resulting binary ends up linking in BOTH their new libc++ runtime and Linux's historical libstdc++, which obviously bombs at runtime. Whether there's a way to compile an app with only libc++ is up for debate; I couldn't do it but would love to be proven wrong.

Still, leaving c++11 compliance & runtimes aside, building code with Clang under Linux is IMHO very much worth it because error reporting is waaaay more useful than g++. Great news... as long as you don't get carried away by promises about c++11 features that just aren't there.

-- p

Re: C++11 compilation sanity check

Posted: Thu Dec 26, 2013 5:13 pm
by eranif
petah wrote:Clang under Linux is IMHO very much worth it because error reporting is waaaay more useful than g++
I upgraded to GCC 4.8.1 on Windows and to my surprise the reporting is looking similar to clang++ ...

Eran

Re: C++11 compilation sanity check

Posted: Thu Dec 26, 2013 5:18 pm
by petah
eranif wrote:I upgraded to GCC 4.8.1 on Windows and to my surprise the reporting is looking similar to clang++ ...
you mean with the "squiggles" (^^^^^^^error here) and all? Could it be due to CL's error detection regexes?

-- p

Re: C++11 compilation sanity check

Posted: Thu Dec 26, 2013 5:20 pm
by eranif
No, codelite has nothing to do with it ... its g++

Eran

Re: C++11 compilation sanity check

Posted: Thu Dec 26, 2013 5:25 pm
by petah
ok I vote for "twilight zone" then :) When I get errors under gcc, whether v4.7 or v4.8.1, it's often lots of noise... especially when templates are involved.

-- p

Re: C++11 compilation sanity check

Posted: Sun Dec 29, 2013 2:15 pm
by petah
* I just noticed gcc 4.8's '^' column error indicator... which I guess was a "quickie" :) Clang's error messages are still much more detailed IMHO.

On a related note, if you need to write regexes on a non-fully-C++11 runtime (like libstdc++) I found Google's open-sourced "RE2" library very nice and compact.

cheers,

-- p

Re: C++11 compilation sanity check

Posted: Sat Jan 04, 2014 10:21 pm
by petah
to subsantiate my earlier claim that error reporting is way better in Clang than gcc, I came across a pretty rare error when trying to convert a std::string to wxString before passing it to wxFileName.

Here's gcc's error report:
gcc_481_error.png
and Clang's:
clang_error.png
The solution is:

Code: Select all

wxFileName cfn((wxString(path)));
I probably wouldn't have figured it out without Clang...

cheers,

-- p

Re: C++11 compilation sanity check

Posted: Sun Jan 05, 2014 5:37 pm
by eranif
Indeed, a rare error (never encounter it before)
1:0 clang

Eran

Re: C++11 compilation sanity check

Posted: Mon Jan 06, 2014 12:29 am
by petah
the "fixit" suggestions are really good too, I was wondering if I could write regexes to turn them into a "suggested fix" message with one-click apply button but then I found http://clang.llvm.org/docs/UsersManual. ... ble-fixits ! It'd probably cover most typos and be pretty reliable since you don't have to juggle regexes.

cheers,

-- p