Sep 2, 2025

[clang] attribute enable_if

enable-if
int isdigit(int c);
int isdigit(int c) __attribute__((enable_if(c <= -1 || c > 255, "chosen when 'c' is out of range"))) __attribute__((
	unavailable("'c' must have the value of an unsigned char or EOF")));

void foo(char c) {
  isdigit(c);
  isdigit(10);
  isdigit(-10);  // results in a compile-time error; as like static_assert.
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.