This is an archive of the discontinued LLVM Phabricator instance.

MathExtras.h: add LLVM_CONSTEXPR where simple
ClosedPublic

Authored by hubert.reinterpretcast on Jul 26 2016, 10:57 AM.

Details

Summary

This change adds LLVM_CONSTEXPR to functions selected as follows:

  • the body is already valid under C++11 for a constexpr function,
  • the evaluation of the function, given constant arguments, will not fail during the evaluation of a constant expression, and
  • the above properties are easily verifiable at a glance.

Note: the evaluation of the function cannot fail if the instantiation triggers a static assertion failure.

Diff Detail

Event Timeline

hubert.reinterpretcast retitled this revision from to MathExtras.h: add LLVM_CONSTEXPR where simple.
hubert.reinterpretcast updated this object.
hubert.reinterpretcast added a subscriber: cfe-commits.
aaron.ballman added inline comments.Jul 28 2016, 7:42 AM
include/llvm/Support/MathExtras.h
672

Usually preferred to put in && "rationale goes here" for asserts (here and elsewhere).

Were these changes expected, as they don't seem to relate to constexpr?

include/llvm/Support/MathExtras.h
672

Sure, I can add the "friendly text".

Also, these changes are expected. The behaviour of these functions when Align is 0 is the reason why I did not modify them so that they may be marked constexpr (according to the language).

aaron.ballman accepted this revision.Jul 29 2016, 5:58 AM
aaron.ballman edited edge metadata.

LGTM, thank you!

include/llvm/Support/MathExtras.h
672

Ah, okay, that makes sense to me. Thank you! Go ahead and add the friendly text when you commit (no need to review further).

This revision is now accepted and ready to land.Jul 29 2016, 5:58 AM