c++ - Why is one expression constant, but not the other? -
why visual studio 2013 compiler reject first static assert (error c2057), not second?
#include <limits> typedef int frequency; const frequency minhz{ 0 }; const frequency maxhz{ std::numeric_limits<frequency>::max() }; const frequency invalidhz{ -1 }; static_assert(minhz < maxhz, "minhz must less maxhz"); // c2057 static_assert(invalidhz < minhz || invalidhz > maxhz, "invalidhz valid"); // ok
i'd guess that, in implementation, max() isn't constexpr (as c++11 says should be), maxhz isn't constant expression, while minhz , invalidhz are.
thus first assert fails because can't evaluated @ compile time; second succeeds, because comparison before || true, second comparison isn't evaluated.
Comments
Post a Comment