From dd8fc629d75f0d9fbd251b5890482513204469d3 Mon Sep 17 00:00:00 2001 From: Max Bozzi Date: Thu, 3 Jan 2019 14:05:55 -0500 Subject: [PATCH] Remove claims that "constexpr functions are pure" (#1307) F.4 and F.8 made this erroneous claim as parts of notes which are entirely removed. --- CppCoreGuidelines.md | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 777afb7..f727a73 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -2601,25 +2601,6 @@ it just guarantees that the function can be evaluated at compile time for consta ##### Note -`constexpr` functions are pure: they can have no side effects. - - int dcount = 0; - constexpr int double(int v) - { - ++dcount; // error: attempted side effect from constexpr function - return v + v; - } - -This is usually a very good thing. - -When given a non-constant argument, a `constexpr` function can throw. -If you consider exiting by throwing a side effect, a `constexpr` function isn't completely pure; -if not, this is not an issue. -??? A question for the committee: can a constructor for an exception thrown by a `constexpr` function modify state? -"No" would be a nice answer that matches most practice. - -##### Note - Don't try to make all functions `constexpr`. Most computation is best done at run time. @@ -2795,16 +2776,6 @@ Pure functions are easier to reason about, sometimes easier to optimize (and eve template auto square(T t) { return t * t; } -##### Note - -`constexpr` functions are pure. - -When given a non-constant argument, a `constexpr` function can throw. -If you consider exiting by throwing a side effect, a `constexpr` function isn't completely pure; -if not, this is not an issue. -??? A question for the committee: can a constructor for an exception thrown by a `constexpr` function modify state? -"No" would be a nice answer that matches most practice. - ##### Enforcement Not possible.