Hacker News new | ask | show | jobs
by s-luv-j 1764 days ago
Is it just me, or have C++ errors gotten a lot better? Below example from guide seems a lot more ergonomic than in years past.

  test.cpp: In instantiation of ‘T add(T, T) [with T = std::basic_string<char>]’:
  test.cpp:17:21:   required from here
  test.cpp:11:22: error: static assertion failed
   11 |   static_assert(std::is_integral_v<T>);
      |                 ~~~~~^~~~~~~~~~~~~~~~
  test.cpp:11:22: note: ‘std::is_integral_v<std::basic_string<char> >’ evaluates to false
Build finished with error(s).
8 comments

One of clang’s stated goals is “expressive diagnostics”

See https://clang.llvm.org/diagnostics.html ; that page is not dated, but compares to gcc 4.9, which is from April 22, 2014.

gcc also has worked on improving its error messages (most likely because of competition with clang), so that comparison probably isn’t accurate anymore.

The link leads to a 404.
The comment markup parser mistakenly understood the link to include the following semicolon, but you couldn’t clearly see it because the semicolon’s descender hid the underline.
Thanks; HN thought the semicolon was part of the URL. Added a space.
There has been more interest from modern programming languages and modern compiler developers in good diagnostics in two ways: 1. The earlier you report the problem, the cheaper the fix and 2. The better the diagnostic the more likely the programmer's fix is appropriate to the actual problem they had.

I agree this is great news. I actually had to write MS SQL for the first time last week and it was disappointing but sadly expected to have it respond to a common but not technically-standard SQL syntax I'm used to with "Syntax error" as though somehow that's helpful. Such poor errors meant I spent more time reading the documentation than writing queries even though I've years of experience across several other SQL dialects.

Yeah, and besides the focus on error messages in past years, concepts will naturally allow template errors to be a _lot_ clearer, since they can serve as the specification of templated type requirements.
One of the major motivations for concepts is to allow better error messages.
And ironically it’s questionable if it helps. Worse error messages were one of the main reasons it got blocked from 17.
It's not just you, dinostics continuously and noticably improve. A lot of effort is spent on this.
Yes. I had build failures related to LTO on our production code that uses gcc 7.5 (Ubuntu 18.04). I had to build it with gcc 9.1 (Ubuntu 20.04) in order to get a useful error message that saved me an hour or two of faffing about.
clang kinda started the race
And now lags behind in C++20 support, as apparently not everyone is keen to upstream whatever they are doing.

Clang concepts were implemented by one guy.

https://cppcast.com/saar-raz-clang-hacking/

Strange
Actually not that strange.

Apple doesn't really care about C++20. Their LLVM efforts are focused on Objective-C and Swift.

C++ as used on Apple platforms is mostly related to the Metal Shading Language (a C++14 subset) and IO/Driver Kit (an Embedded C++ variant).

Google has their style guide, only recently updated to C++, isn't a compiler vendor and apparently losing on the ABI vote has made several employees move away from their clang involvement.

Then the other vendors like Intel, Embarcadero, IBM, Codeplay, Sony, Nintendo, ARM, NVidia, AMS have their own agendas and do not upstream everything.

That has nothing to do with C++. Its entirely a compiler thing.
Not entirely true - one of the motivations for new features and libraries C++ adds is to make better errors possible. In this case, `static_assert` was added in C++11, and `is_integral_v` was added in C++17. Concepts, the new feature this post is about, falls under that category as well.
True, although the distinction hardly matters to users.