News for hackers. Stuff that matters.
Re:C++17 constexpr everything, or as much as the compiler can by mikepurvis on Thursday December 28, 2017 @03:49PM (#16024771)
There's precedent in C++ for keywords that give the compiler hints it doesn't necessarily promise to act on: inline.
Re:C++17 constexpr everything, or as much as the compiler can by mwkaufma on Thursday December 28, 2017 @06:18PM (#16025982)
Shameless pedant kneejerk: 'inline' has semantics in additional to the optimization-hint. e.g. inlined functions won't trigger multiple-definition link-errors, even if they're left as ordinary functions in the executable.
Re:C++17 constexpr everything, or as much as the compiler can by mehrdadn on Thursday December 28, 2017 @04:34PM (#16025081)
Happy to be corrected (EDIT: indeed, I stand corrected! see replies below), but I don't think the C++ spec says anything about 'inline' encouraging the compiler to inline the compiled code?

'auto' would've been an example, but that also got removed, because they realized it was useless. I don't get how constexpr is any different.

Re:C++17 constexpr everything, or as much as the compiler can by mikepurvis on Thursday December 28, 2017 @05:34PM (#16025617)
I don't know my way around the spec, but Wikipedia is pretty unequivocal:

"... it serves as a compiler directive that suggests (but does not require) that the compiler substitute the body of the function inline by performing inline expansion, i.e. by inserting the function code at the address of each function call, thereby saving the overhead of a function call."

https://en.wikipedia.org/wiki/Inline_function

Re:C++17 constexpr everything, or as much as the compiler can by mehrdadn on Thursday December 28, 2017 @05:49PM (#16025745)
Thanks for this! I was very skeptical, but you made me look through every single mention of the word 'inline' in the spec, and you are indeed correct. :) Here is the relevant quote:

> [7.1.2] [dcl.fct.spec] A function declaration with an inline specifier declares an inline function. The inline specifier indicates to the implementation that inline substitution of the function body at the point of call is to be preferred to the usual function call mechanism. An implementation is not required to perform this inline substitution at the point of call; however, even if this inline substitution is omitted, the other rules for inline functions defined by shall still be respected