https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88683
Bug ID: 88683 Summary: nan <= inf not accepted as constant expression Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mjansche at google dot com Target Milestone: --- I am observing a regression between g++-7.4.0 and g++-8.2.0 when compiling the following code: #include <iostream> #include <limits> int main() { constexpr double nan = std::numeric_limits<double>::quiet_NaN(); constexpr double inf = std::numeric_limits<double>::infinity(); constexpr bool inf_ge_nan = inf >= nan; // accepted std::cout << inf_ge_nan << std::endl; constexpr bool nan_le_inf = nan <= inf; // rejected: not a constant expression std::cout << nan_le_inf << std::endl; return 0; } I have read section 5.19 [expr.const] of the C++11 standard a few times and don't see why the expression (nan <= inf) wouldn't be a constant expression in the above code. This is especially puzzling as (inf >= nan) is considered a constant expression yet (nan <= inf) is not. At a minimum I would expect (inf >= nan) to be a constant expression iff (nan <= inf) is. I wouldn't make too much of the observation that this is a regression between 7.4.0 and 8.2.0: I've seen similar issues in g++-7.3.0, but haven't been able to reproduce them in isolation. Details: $ /usr/local/stow/gcc-7.4.0/bin/g++ -v Using built-in specs. COLLECT_GCC=/usr/local/stow/gcc-7.4.0/bin/g++ COLLECT_LTO_WRAPPER=/usr/local/stow/gcc-7.4.0/libexec/gcc/x86_64-pc-linux-gnu/7.4.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-7.4.0/configure --prefix=/usr/local/stow/gcc-7.4.0 Thread model: posix gcc version 7.4.0 (GCC) $ /usr/local/stow/gcc-8.2.0/bin/g++ -v Using built-in specs. COLLECT_GCC=/usr/local/stow/gcc-8.2.0/bin/g++ COLLECT_LTO_WRAPPER=/usr/local/stow/gcc-8.2.0/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-8.2.0/configure --prefix=/usr/local/stow/gcc-8.2.0 Thread model: posix gcc version 8.2.0 (GCC) $ /usr/local/stow/gcc-7.4.0/bin/g++ -std=c++11 -Wall -Wextra nan_le_inf.cc $ /usr/local/stow/gcc-8.2.0/bin/g++ -std=c++11 -Wall -Wextra nan_le_inf.cc nan_le_inf.cc: In function βint main()β: nan_le_inf.cc:8:35: error: β(+QNaN <= +Inf)β is not a constant expression constexpr bool nan_le_inf = nan <= inf; // rejected: not a constant expression ~~~~^~~~~~