Advertisement
Guest User

Clang, constexpr, bitshift

a guest
Sep 25th, 2015
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <climits>
  2. using namespace std;
  3.  
  4. template <typename T> constexpr unsigned bits() {
  5.     return sizeof(T) * CHAR_BIT;
  6. }
  7.  
  8. int main() {
  9.     constexpr int a = 1; // obviously fine
  10.     constexpr int b = bits<int>(); // fine
  11.     constexpr int c = 1 << 3; // fine
  12.     constexpr int d = 1 << bits<int>(); // error: constexpr variable 'd' must be initialized by a constant expression
  13.     constexpr int e = 1 + bits<int>(); // fine
  14.     return 0;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement