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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -