C++ Weekly - Ep 444 - GCC's Implicit constexpr

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

Upcoming Workshops:

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

Рекомендации по теме
Комментарии
Автор

Someone should submit a proposal to make all functions implicitly constexpr, if they can be. Lambdas already have this behavior so most implementations already know how to do it and it should be backwards compatible, so it doesn't sound like a bad idea.

abhinavk
Автор

implicit constexpr goes against the C++ design rule of "let's make everything shitty by default, but terribly customizeable so that if you decorate your code with all kinds of warts you can produce pretty efficient and safe code"

urisimchoni
Автор

May be useful for testing the net benefit of constexpring old code before doing all the work of manually altering the source code. Although even for such a test case if you still need to go through and "inline" everything first, so how much time are you really saving. Probably very case by case dependent.

mytech
Автор

Does this only happen in GCC? Could it happen to Clang when using GCC's standard library as well?

heavymetalmixer
Автор

Maybe we can use this flag to get constexpr from 3rd party libraries sometimes?

Sebanisu
Автор

Wait...what ? Constexpr variables are automagically captured in the lambda? Didn't know about that. Disturbing...
Anyway, thanks for sharing Jason.

sebastienlevy
Автор

Does -O3 take this into consideration?

bcodetube
Автор

Might be interesting if there is an implicit inline or similar mechanism for Release builds with GCC, especially if the STL gets implicitly constexpr'd if possible, or if GCC has some additional constexpr extensions

Xilefian
Автор

I would love to have implicit const too... make it like rust where you use a keyword to make things mutable

ruadeil_zabelin
Автор

I wonder if this can break code. I guess one might have libraries that are not constexpr friendly and not compile. i am going to start testing my code (libraries) to see if it works in combination with this flag.

AlfredoCorrea
Автор

seems like bots really love watching jason's video /s

nirajandata
Автор

I'll say it again even though no one will read this or agree if they did, but I think the language should've just defaulted to constexpr/consteval all the things and fall back to non-const if const wasn't possible. I also think that they should have enhanced the const keyword so that using it was a check on whether something could be constexpr/consteval'd and result in an error when it can not. Also, I'd really like to know if there's a platform that Clang runs on that GCC doesn't also run on, because I disagree with the advice about only targeting one compiler when that compiler is GCC because it runs nearly everywhere and has more cross compilers than you can shake a stick at. If you merely said don't always use MSVC, then of course I'd agree because it has a much more limited set of platforms that it runs on.

anon_y_mousse
Автор

Too bad you have to give Microsoft both of your arms and a leg to get GCC working [natively] on Windows.

skeleton_craftGaming
Автор

Honestly I don't see the point of constexpr, it only works if the values in the equation are known at compile time, in which case the compiler would be able to optimise (evaluate) the equation anyway.

axelBr
join shbcf.ru