[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 25 15:26:05 PST 2018


MaskRay added a comment.

https://reviews.llvm.org/rC347417 makes `constexpr string_view service = "HELLO WORD SERVICE"` (P0426) broken with libstdc++

  % cat a.cc
  constexpr bool __constant_string_p(const char *__s) {
    while (__builtin_constant_p(*__s) && *__s)
      __s++;
    return __builtin_constant_p(*__s);
  }
  
  constexpr bool n = __constant_string_p("a");



  % fclang++ -std=c++17 -fsyntax-only a.cc
  a.cc:1:16: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  constexpr bool __constant_string_p(const char *__s) {
                 ^
  a.cc:2:10: note: subexpression not valid in a constant expression
    while (__builtin_constant_p(*__s) && *__s)
           ^
  a.cc:7:16: error: constexpr variable 'n' must be initialized by a constant expression
  constexpr bool n = __constant_string_p("a");
                 ^   ~~~~~~~~~~~~~~~~~~~~~~~~
  a.cc:2:10: note: subexpression not valid in a constant expression
    while (__builtin_constant_p(*__s) && *__s)
           ^
  a.cc:7:20: note: in call to '__constant_string_p(&"a"[0])'
  constexpr bool n = __constant_string_p("a");
                     ^
  2 errors generated.

Fourth time should be a charm...


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54355/new/

https://reviews.llvm.org/D54355





More information about the cfe-commits mailing list