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

p1378 - std::is_string_literal(const T*) for C++29 #18

Open
ThePhD opened this issue Feb 25, 2019 · 5 comments
Open

p1378 - std::is_string_literal(const T*) for C++29 #18

ThePhD opened this issue Feb 25, 2019 · 5 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed humans [design.lewg] To be mulled over by the sometimes rowdy, generally level-headed, but often weird people in LEWG. research Digging into the problem at hand
Milestone

Comments

@ThePhD
Copy link
Owner

ThePhD commented Feb 25, 2019

Determining whether a string is a string literal gives us certain guarantees about memory layout and null termination. The goal is to write a consteval function that covers this landscape area.

@ThePhD ThePhD added enhancement New feature or request help wanted Extra attention is needed research Digging into the problem at hand labels Feb 25, 2019
@ThePhD ThePhD added this to the C++23 milestone Feb 25, 2019
@ThePhD ThePhD self-assigned this Feb 25, 2019
@ThePhD ThePhD changed the title pXXXX - std::is_string_literal(const char*) for C++23 pXXXX - std::is_string_literal(const T*) for C++23 Feb 25, 2019
@ThePhD
Copy link
Owner Author

ThePhD commented Feb 25, 2019

Note that is_static_storage_duration makes subtly different guarantees: notably, there may not be interning, it may not be a string literal, etc.

@ThePhD ThePhD added the humans [design.lewg] To be mulled over by the sometimes rowdy, generally level-headed, but often weird people in LEWG. label Jun 10, 2019
@ThePhD ThePhD changed the title pXXXX - std::is_string_literal(const T*) for C++23 p1378 - std::is_string_literal(const T*) for C++23 Jun 11, 2019
@ThePhD
Copy link
Owner Author

ThePhD commented Jun 20, 2019

Submitted for LEWG, Köln, Germany 2019 for inclusion in C++23.

@ThePhD ThePhD changed the title p1378 - std::is_string_literal(const T*) for C++23 p1378 - std::is_string_literal(const T*) for C++26 Sep 25, 2020
@ThePhD
Copy link
Owner Author

ThePhD commented Sep 25, 2020

The utility of this is going to need more motivation; until then, it's going to be targeted at C++26 to take the pressure off.

@ThePhD ThePhD modified the milestones: C++23, C++26 Sep 25, 2020
@ThePhD
Copy link
Owner Author

ThePhD commented Jun 20, 2022

Moved to C++29. It also might be impossible to implement at all, so it might be time to close this one entirely.

@ThePhD ThePhD changed the title p1378 - std::is_string_literal(const T*) for C++26 p1378 - std::is_string_literal(const T*) for C++29 Jun 20, 2022
@frederick-vs-ja
Copy link

This seems (partially?) implementable if we can restore constant evaluation from failure.

template<class CharT>
consteval bool is_string_literal(const CharT* p) noexcept {
  try consteval { // constant evaluation failure inside the try-consteval block is caught and ignored
    while (*p != CharT{})
      ++p;
    return true;
  }
  return false;
}

Perhaps the __builtin_constant_p extension is already capatible for implementing the utility (Godbolt link)?

template<class CharT>
constexpr bool is_string_literal_helper(const CharT* p) noexcept {
  while (*p != CharT{})
    ++p;
  return true;
}

template<class CharT>
consteval bool is_string_literal(const CharT* p) noexcept {
  return __builtin_constant_p(::is_string_literal_helper(p));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed humans [design.lewg] To be mulled over by the sometimes rowdy, generally level-headed, but often weird people in LEWG. research Digging into the problem at hand
Projects
None yet
Development

No branches or pull requests

2 participants