5 ms·
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
by codebeaker 10y ago
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.
- oblio 10y agoOr even better, at some point they should introduce "safe mode" or "strict mode", where you turn on a compiler flag.
- cygx 10y agoaka -Weverything ;)
- tomsmeding 10y agoWhich is hella annoying. -Wall -Wextra is very needed, -Wconversion is nice but already borderline annoying, but enabling everything would just be a mess.
- lorenzhs 10y ago-Wc++98-compat is especially annoying.
- uabstraction 10y agoYou guys don't use -pedantic? :D
- lorenzhs 10y ago-Weverything is even more pedantic than -pedantic: http://clang.llvm.org/docs/UsersManual.html#diagnostics-enable-everything http://clang.llvm.org/docs/UsersManual.html#diagnostics-enab... - pedantic can be a bit annoying, but Weverything is downright infuriating on a modern codebase
- cygx 10y agoThat'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=""
- adrianN 10y agoclang-tidy does this (or is working towards doing this) http://clang.llvm.org/extra/clang-tidy/checks/list.html http://clang.llvm.org/extra/clang-tidy/checks/list.html
- codebeaker 10y agoThanks, that page looks like hell, but I recognise a few terms. http://clang.llvm.org/extra/clang-tidy/ 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.
- masklinn 10y ago> Then why is it called tidy ??? https://en.wikipedia.org/wiki/HTML_Tidy https://en.wikipedia.org/wiki/HTML_Tidy
- andystanton 10y agoIt's also a (possibly unintentional) play on the British slang term "bang tidy" http://www.collinsdictionary.com/dictionary/english/bang-tidy http://www.collinsdictionary.com/dictionary/english/bang-tid...
- pjmlp 10y agoThat 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.