News for hackers. Stuff that matters.
Re:A list of modern C++ features by codebeaker on Monday November 14, 2016 @02:31AM (#12948107)
I really wish there would be a linter (I realise it's probably a nearly impossible task) which would complain when you use legacy, unsafe language features.

As someone who doesn't work in C++ or have the benefit of 10 years experience to see the flaws, trying to write modern, safe C++ is essentially impossible. I spent a solid week trying to write something safe and only use C++14/17 features when they were available, and encountered a mountain of outdated- and mis-information about what one can and can't do, what is and isn't considered safe and why one certain feature is better than another.

It's nobody's fault that this happens, but with C++14 apparently fast becoming a language that is addressing it's #1 pitfall (safety) in an apparently very adequate way, it's frustrating that there's no "safe code" linter to stop rookies stepping on landmines.

Thanks for the list, it's a solid start, and the sibling comment about C++ Core Guidelines is another solid resource.

Re:A list of modern C++ features by adrianN on Monday November 14, 2016 @03:39AM (#12948374)
clang-tidy does this (or is working towards doing this)

http://clang.llvm.org/extra/clang-tidy/checks/list.html

Re:A list of modern C++ features by codebeaker on Monday November 14, 2016 @03:57AM (#12948451)
Thanks, that page looks like hell, but I recognise a few terms.

http://clang.llvm.org/extra/clang-tidy/ is much more approachable, and gives a solid overview.

The introductory sentence gave me project-naming cancer:

> clang-tidy is a clang-based C++ “linter” tool.

Then why is it called tidy ??? It appears first on page three of google's search results for "C++ linter" in spite of the fact that anything from LLVM is probably a) current and b) of exceptional quality.

A little marketing-mindset would go a long, long way for these kinds of things.

Whilst the Ruby community lead by the example of DHH often takes this concept too far, it is inarguably effective.

Re:A list of modern C++ features by masklinn on Monday November 14, 2016 @05:32AM (#12948803)
> Then why is it called tidy ???

https://en.wikipedia.org/wiki/HTML_Tidy

Re:A list of modern C++ features by andystanton on Monday November 14, 2016 @09:38AM (#12950014)
It's also a (possibly unintentional) play on the British slang term "bang tidy" http://www.collinsdictionary.com/dictionary/english/bang-tid...
Re:A list of modern C++ features by pjmlp on Monday November 14, 2016 @04:35AM (#12948598)
That is what Microsoft introduced at CppCon 2015 alongside the C++ Core Guidelines.

Besides the clang-tidy, there is the ongoing efforts to improve VS analyzers, but I guess they will only be fully productized on VS "15", the upcoming release.

I also imagine other C++ linters are improving their C++ Core Guidelines support.

Under C++ Core Guidelines you are supposed to use [[unsafe]] annotation to mark such features.

Re:A list of modern C++ features by oblio on Monday November 14, 2016 @03:31AM (#12948347)
Or even better, at some point they should introduce "safe mode" or "strict mode", where you turn on a compiler flag.
Re:A list of modern C++ features by cygx on Monday November 14, 2016 @08:23AM (#12949644)
aka -Weverything ;)
Re:A list of modern C++ features by tomsmeding on Monday November 14, 2016 @10:59AM (#12950618)
Which is hella annoying. -Wall -Wextra is very needed, -Wconversion is nice but already borderline annoying, but enabling everything would just be a mess.
Re:A list of modern C++ features by lorenzhs on Monday November 14, 2016 @11:07AM (#12950665)
-Wc++98-compat is especially annoying.
Re:A list of modern C++ features by uabstraction on Monday November 14, 2016 @12:34PM (#12951539)
You guys don't use -pedantic? :D
Re:A list of modern C++ features by lorenzhs on Monday November 14, 2016 @02:57PM (#12952714)
-Weverything is even more pedantic than -pedantic: http://clang.llvm.org/docs/UsersManual.html#diagnostics-enab... - pedantic can be a bit annoying, but Weverything is downright infuriating on a modern codebase
Re:A list of modern C++ features by cygx on Monday November 14, 2016 @10:06PM (#12955294)
That's why you combine it with -Wno-... as appropriate on a per-project as well as per-file basis in addition to a simple way to disable warnings completely.

When using make, it could look something like this:

    CC := clang
    CFLAGS := -std=c99
    WFLAGS := -Weverything -Werror
    NOWARN := vla
    COMPILE = $(CC) -c $(CFLAGS) $(WFLAGS) $(NOWARN:%=-Wno-%) -o $@ $<

    foo.o: NOWARN += padded

    foo.o bar.o: %.o: %.c
        $(COMPILE)
Building without warnings would be achieved via

    make WFLAGS=""