次のコードがあります。
uint16_t getLastMarker(const std::string &number);
...
const auto msgMarker = getLastMarker(msg.number) + static_cast<uint16_t>(1);
static_assert(std::is_same<decltype(msgMarker), const int>::value, "Should fail");
static_assert(std::is_same<decltype(msgMarker), const uint16_t>::value, "Should not fail");
最初のアサーションは失敗し、2 番目のアサーションは失敗しないと思います。ただしgcc 4.9.2
、clang 3.6
反対のことを行います。コードで auto の代わりに uint16_t を使用すると、適切なアサーションが失敗し、別のアサーションが成功します。
PS最初は、1
代わりにstatic_cast<uint16_t>(1)
、数値リテラルがint型であるという事実が問題の原因であると考えていましたが、1
ここで明示的にキャストした後でも間違ったアサーションが失敗しました。