fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
20.75k stars 2.5k forks source link

FMT_STRING does not compile with "if constexpr()" #1455

Closed rianquinn closed 4 years ago

rianquinn commented 4 years ago

If you attempt to compile FMT_STRING with an if constexpr, you get the following with GCC 9

if constexpr (contracts_throw && !autosar_compliant) {
    std::string s = fmt::format(FMT_STRING("{}"), "foo");
}
/home/rianquinn/working/bsl/tests/int/../../include/bsl/contracts.hpp:120:68: error: invalid use of void expression
  120 |                 std::string s = fmt::format(FMT_STRING("{}"), "foo");
rianquinn commented 4 years ago

If I remove the constexpr, this works fine.

eliaskosunen commented 4 years ago

Looks like a bug with gcc: https://godbolt.org/z/krYNm9 If you look at the error messages, gcc thinks that the return type of the lambda is void, while clang correctly detects it to be str. This only happens if the if constexpr condition evaluates to false.