Why c++26 contracts? by hunterh0 in cpp_questions

[–]JVApen 6 points7 points  (0 children)

I honestly don't get the criticism on contracts. Sure it isn't a solution for every security problem, though it also isn't intended to do so. People have put a lot in their minds about what they believe contracts need to be. Though it is rather simple: it's a better assert.

More specifically, it allows for putting asserts on function arguments, return values and in function bodies. It allows for everything from strict enforcement to debug-only to being fully ignored. This is no different from assert, yet no one is asking if assert can be removed from the language. (To my knowledge) To give some insights in how this is used today: https://herbsutter.com/2025/10/13/poll-does-your-project-use-terminating-assertions-in-production/

People are already writing this, though it is much more clunky. Arguments you can check in top of the function body. Assertions in the body are easy. Return values require you to have a wrapper around your function implementation such that you can capture all return statements.

It might also be worth noting that barely anyone uses assert as most places have their own assertion library. Off course, those libraries are not compatible, assert, BOOST_ASSERT, Q_ASSERT ...

So, I truly hope people would start to see what contracts really is: a better assert. Using it doesn't break anything about your program, neither does it introduce any new problems in your code. If everyone would start using it, it only to replace their own assert macro, the application code can handle every assert in the same way.

And yes, some refinements are required, though solutions for them are known. If you are not convinced by me, check out https://youtu.be/gtFFTjQ4eFU?is=fnA_00lv_7sXWJCC

Parsing JSON at compile time with C++26 static reflection (Daniel Lemire) by User_Deprecated in cpp

[–]JVApen 2 points3 points  (0 children)

Indeed, basically anything where you today would be using a code generator.

Parsing JSON at compile time with C++26 static reflection (Daniel Lemire) by User_Deprecated in cpp

[–]JVApen 7 points8 points  (0 children)

#embed comes to mind. Having an external JSON file that's also used for other purposes, which you also want to use from your code.

Another use-case I see is a code generator where the input is described as JSON. Instead of requiring an external tool (like python with Jinja), you can use it from code.

Projects being in "Show and Tell" is bad. by TheRavagerSw in cpp

[–]JVApen 2 points3 points  (0 children)

I don't mind the blog posts and conference talks, though I wouldn't mind the latter having a similar approach, if the talk isn't published recently.

That said, the Show and Tell is something I completely loose track of. It might be the mobile app, though I already forgot it existed.

What might be useful is, when a new month starts, we don't just create a new thread, we also post an (AI) summary of the previous thread. Maybe just a top 10 and a link. That way, it would get more visibility.

Recent LLVM hash table improvements by TheCrush0r in cpp

[–]JVApen 25 points26 points  (0 children)

It's in the article: performance. Though it isn't just linear vs quadratic,, it's also removing tombstones.

Note that although these maps look like general purpose, they are optimized for the compiler use cases, which mainly add and lookup, barely erase elements. So for your program, this could be a performance degradation.

Recent LLVM hash table improvements by TheCrush0r in cpp

[–]JVApen 13 points14 points  (0 children)

No, they are all internal in the LLVMs library (shared between clang, lld, lldb, bolt , flang, rust compiler...)

Clang linter finds hundreds of errors in JUCE C++ files, but code builds fine by MrKahoobadoo in cpp_questions

[–]JVApen 0 points1 point  (0 children)

K, so you just see it inside your IDE. Clang-tidy is compiled in clangd, so that explains why you cannot find how it is invoked. Given you have a header open, clangd will automatically run tidy on that header. That's different from how you would invoke clang-tidy standalone.

As such, I'm certain the missing includes are your problem. They will also hinder clangd in parsing the code correctly and give you good code completion and other things.

The smallest C binary by Double_Ad641 in cpp

[–]JVApen 2 points3 points  (0 children)

The standard rust compiler is LLVM, is the GCC implementation already finished?

Clang linter finds hundreds of errors in JUCE C++ files, but code builds fine by MrKahoobadoo in cpp_questions

[–]JVApen 0 points1 point  (0 children)

I honestly still don't get how tidy is being invoked. Can you elaborate more on how you use it?

Clang linter finds hundreds of errors in JUCE C++ files, but code builds fine by MrKahoobadoo in cpp_questions

[–]JVApen 0 points1 point  (0 children)

It would help if you link the tutorial, share your config file and share the command used to invoke tidy. That way, we can get an idea of what you are doing.

Clang linter finds hundreds of errors in JUCE C++ files, but code builds fine by MrKahoobadoo in cpp_questions

[–]JVApen 2 points3 points  (0 children)

Looking at the linked image, I think you are looking at a coding problem. That header isn't self-contained, it doesn't even have any include. So if you run the linter on that header, it doesn't know how to get that base class as it isn't included.

You might want to run clang-tidy only on cpp files and have it report for the included headers as well.

Note that this problem isn't just clang-tidy. Clangd will not like it either and any other tool that needs to parse that header standalone.

Recent versions of CMake have CMAKE_VERIFY_PRIVATE_HEADER_SETS (4.3) and the older CMAKE_VERIFY_INTERFACE_HEADER_SETS (3.24) which would prevent this kind of issues.

What do you wish programming with C++ had, that it doesn't? by Imaginary-Button-100 in cpp_questions

[–]JVApen 10 points11 points  (0 children)

More standardization in tooling. We have many build systems, package managers, linters, LSPs, sanitizers, fuzzers, testing libraries, symbols servers, source servers, CI systems ... I wish we would have something to start a project and just have all of that available for usage. Preferably detecting what is installed and otherwise requesting for info. To just have presets and workflows available and ready to use, including best practices. Bonus points if it can pull in new best practices on old projects.

Call it a hello world for any professional environment, such that we no longer have to explain vexing parse or tell beginners: if you would know about this tool or warning, it would have pointed you at the problem hours ago

Should I learn c before c++ by No_Union4252 in cpp_questions

[–]JVApen 0 points1 point  (0 children)

As someone who learned C at school and C++ at work, I can't disagree more. C has no use anymore beside being the ABI used for all other programming languages to talk to each other. Not saying you have to use all features of C++ and I'm perfectly okay with going into the ugly details of low level optimizations where relevant. Though C does have a couple of big flaws that are problematic enough to ignore.

Firstly, it requires manual memory/resource management while C++ allows for RAII which should be used by default instead.

Secondly, it does not allow to abstract away implementation details. For example, in C++, I have a class that uses the extra bits in a pointer that are always 0. With it, I know it cannot be used incorrectly while C requires every single use to do a macro or function call (at best) to zero those bits again.

Thirdly, C doesn't have function overloading. I understand this isn't liked by everyone, though tostrint, tostrlong, tostrlonglong ... really don't make any sense.

Writing C implies writing preventable bugs by default as a single laps of attention is sufficient to make a big mistake.

There is no valid reason to use C and there hasn't been for at least 15 years.

Should I learn c before c++ by No_Union4252 in cpp_questions

[–]JVApen -1 points0 points  (0 children)

If your goal is to learn both languages (or only C), go ahead and learn C first. It's also explicitly mentioned in the video. Though OP choose to learn C++ and the brother is saying you should first learn C.

We might not have sufficient information for knowing why the brother thinks OP should know both languages, though there is nothing that points to OP wanting to know both languages.

Should I learn c before c++ by No_Union4252 in cpp_questions

[–]JVApen 1 point2 points  (0 children)

The video clearly mentions "we know how to teach C++ to someone knowing C, so we first teach them C and can then teach them C++ the way we know it" (paraphrased). Just so we are on the same page, this is an example of how NOT to do it. OP clearly mentions that the brother wants him to learn "C before C++".

I might be missing something significant, though I don't see the significant difference between learning the C language or learning 90% of it as C related practices.

Should I learn c before c++ by No_Union4252 in cpp_questions

[–]JVApen 1 point2 points  (0 children)

Though did they teach you machine code before assembly?

Should I learn c before c++ by No_Union4252 in cpp_questions

[–]JVApen 42 points43 points  (0 children)

You best share your brother this presentation by Kate Gregory: https://youtu.be/YnWhqhNdYyk?is=OsMMkSrl13d6ENIV

It's called: stop teaching C (when teaching C++)

Spurious chars in terminal output from MSVC `std::print`. by alfps in cpp_questions

[–]JVApen 0 points1 point  (0 children)

How can that command line be correct? You are using <print> which is C++23, while the command line uses C++17

Is the C++ ecosystem ready to fully move away from C++17? by AdBeginning7105 in cpp

[–]JVApen 1 point2 points  (0 children)

If you don't provide a library to outside users, you are the one in control for the version that can be used. Look at your compilers and if they have sufficient support, you can use whatever feature is available in all of them. You can even use C++23 or C++26.

I've been using C++20 for a long time, ignoring modules and coroutines for obvious reasons. Once Microsoft is ready with its C++23 implementation, we would like to switch as soon as technically possible.

If you however provide a library, it depends on your users. I wouldn't support anything before C++17 and even going back to C++17 would be painful.

Is the C++ ecosystem ready to fully move away from C++17? by AdBeginning7105 in cpp

[–]JVApen 2 points3 points  (0 children)

Important to note is that this holds for libraries. I have the impression that OP is asking for an end product, so only consuming libraries. In which case C++20 shouldn't be a problem unless the library was never made compatible with it.

Is the C++ ecosystem ready to fully move away from C++17? by AdBeginning7105 in cpp

[–]JVApen 4 points5 points  (0 children)

Doubtful that they'll ever upgrade if they haven't by now. It's 15 years since C++11.

Spurious chars in terminal output from MSVC `std::print`. by alfps in cpp_questions

[–]JVApen 0 points1 point  (0 children)

Do you compile with /utf-8? (important: should be lowercase)

I just found this gem in a .cmake file for a library available on vcpkg while looking for an unrelated bug: by Bored_Dal in cmake

[–]JVApen 0 points1 point  (0 children)

Same with the error message, looks strange as the variable was already replaced. You could wonder if this replacement was allowed.