Reduced example from https://stackoverflow.com/q/51053280/2069064: int global = 0; constexpr int f(bool arg) { if (arg) { return 1; } return global++; } Fails on gcc trunk with: <source>: In function 'constexpr int f(bool)': <source>:8:1: error: the value of 'global' is not usable in a constant expression } ^ <source>:1:5: note: 'int global' is not const int global = 0; ^~~~~~ Compiler returned: 1 But the function is fine. The near-equivalent formulation of constexpr int g(bool arg) { if (arg) { return 1; } else { return global++; } } also compiles fine.
Fixed by r264171, will add the test.
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:4ded16a7782fd3a9e7b37291d04bca596b00b8bd commit r10-7688-g4ded16a7782fd3a9e7b37291d04bca596b00b8bd Author: Marek Polacek <polacek@redhat.com> Date: Sat Apr 11 10:45:33 2020 -0400 c++: Add test for PR 86327. Fixed by r264171. PR c++/86327 * g++.dg/cpp1y/constexpr-return5.C: New test.
Fixed in GCC 9.