Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it proper to always use std:: on C functions mentioned in examples? #7250

Open
Myriachan opened this issue Sep 8, 2024 · 2 comments
Open

Comments

@Myriachan
Copy link

[meta.const.eval] has this code example:

constexpr void f(unsigned char *p, int n) {
  if (std::is_constant_evaluated()) {           // should not be a constexpr if statement
    for (int k = 0; k<n; ++k) p[k] = 0;
  } else {
    memset(p, 0, n);                            // not a core constant expression
  }
}

Should this say std::memset instead of memset to be more consistent with the rest of C++? There are a few other cases in which std:: is omitted for C standard functions.

This is being rather pedantic, because anyone reading the Standard would know what is meant by memset here.

@jwakely
Copy link
Member

jwakely commented Sep 8, 2024

It's not a complete example that's supposed to be able to compile. It is valid if it comes after:

#include <cstring>
using std::memset;

I think it would be ok to add the qualification here anyway.

@frederick-vs-ja
Copy link
Contributor

Given there's already if consteval, I think it would be better to show a brand new example which uses std::is_constant_evaluated in a ternary conditional expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants