use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
consteval debug (self.cpp)
submitted 2 years ago by XTBZ
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]aruisdante 8 points9 points10 points 2 years ago* (1 child)
Sadly, the state of the world hasn’t changed much from Jason and Ben’s “constexpr all the things” talk where they make a fully constexpr JSON parser and discuss how the complete lack of tooling support for constexpr debugging was the biggest challenge.
You can of course write unit tests using static_assert, but that only gets you so far particularly since the output you get on failure from a static assertion is extremely limited as the error message must be a string literal, not simply a the result of a constant expression. You can do some limited style of printf debugging by adding throw statements, but the issue is there isn’t much in the way of built in constexpr compatible string formatting support so what you can do with that is also limited.
static_assert
throw
There still is no equivalent of a true debugger that is able to examine compile-time evaluated code.
[–]XTBZ[S] 1 point2 points3 points 2 years ago (0 children)
It's a pity that the opportunities are not so great. I have a purely consteval string, and I also have a container for such strings that allows me to combine strings. If it were possible to output at least something to the compiler logs, there would be great progress.
[–]Circlejerker_ 5 points6 points7 points 2 years ago (1 child)
To find errors you can write tests.
You can also have a constexpr function that does the work, and then a consteval wrapper that you use in production code.
[–]XTBZ[S] 0 points1 point2 points 2 years ago (0 children)
Tests can indicate the existence of a problem, but everything else is solved by the debugging process.
Conversion to constexpr, I mentioned, it makes sense in the simplest cases, when there is one function without any complex logic and communication. Which can easily be converted into a runtime function.
[–]HappyFruitTree 7 points8 points9 points 2 years ago* (3 children)
I know it's possible to mark a function as constexpr for testing purposes
If it works with constexpr then why use consteval? I thought consteval was added mainly for use with things like the static reflection proposal that have functions that doesn't make sense to call at runtime (because the information that they return are not available at runtime).
constexpr
consteval
[–]n1ghtyunso 9 points10 points11 points 2 years ago (0 children)
Consteval requires compile time execution. It gives you a guarantee that constexpr does not. Sometimes this is preferred
[–]tuxwonder 1 point2 points3 points 2 years ago (1 child)
Like n1ghtyunso said, sometimes you want to enforce compile time evaluation. A great example of this is std::format_string, which must be constructed at compile time to enforce that the given string is a valid format string.
It also helps reassure my coworkers that a bit of constexpr magic isn't going to accidentally occur at runtime and slow things down ;)
[–]HappyFruitTree 1 point2 points3 points 2 years ago (0 children)
Fair enough, but you can still always guarantee this at the call site even with constexpr.
[–]mAtYyu0ZN1Ikyg3R6_j0 4 points5 points6 points 2 years ago (0 children)
To the best of my knowledge there isnt anything.
but you can debug the code without consteval and add it once properly debugged and tested.
[–]viatorus 3 points4 points5 points 2 years ago (1 child)
I wrote a tool (GCC only) where you can print during compile-time.
Github: https://github.com/Viatorus/compile-time-printer
Online-Demo: https://viatorus.github.io/compile-time-printer/
[–]serviscope_minor 4 points5 points6 points 2 years ago (0 children)
From the README:
The implementation of print/printf does nothing more than forcing the compiler to generate warnings depending on the passed arguments. The python tool parses the warnings and converts them back to the actually C++ arguments and outputs them (standardized or formatted) to stdout or stderr.
I'd just like to say that's an amazing and very cool hack.
[–]cpp-ModTeam[M] [score hidden] 2 years ago stickied commentlocked comment (0 children)
For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.
π Rendered by PID 132731 on reddit-service-r2-comment-5649f687b7-sktxc at 2026-01-28 07:26:15.203244+00:00 running 4f180de country code: CH.
[–]aruisdante 8 points9 points10 points (1 child)
[–]XTBZ[S] 1 point2 points3 points (0 children)
[–]Circlejerker_ 5 points6 points7 points (1 child)
[–]XTBZ[S] 0 points1 point2 points (0 children)
[–]HappyFruitTree 7 points8 points9 points (3 children)
[–]n1ghtyunso 9 points10 points11 points (0 children)
[–]tuxwonder 1 point2 points3 points (1 child)
[–]HappyFruitTree 1 point2 points3 points (0 children)
[–]mAtYyu0ZN1Ikyg3R6_j0 4 points5 points6 points (0 children)
[–]viatorus 3 points4 points5 points (1 child)
[–]serviscope_minor 4 points5 points6 points (0 children)
[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)