https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85319

            Bug ID: 85319
           Summary: std::char_traits<char>::length does not always
                    function in constexpr context
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: v at vsamko dot com
  Target Milestone: ---

This fails to compile with "error: non-constant condition for static assertion

     static_assert(std::char_traits<char>::length(cstr) == 2);"

```
#include <string>
static constexpr char cstr[3] = {'1', '2', '\0'};

constexpr int foobar() {
    static_assert(std::char_traits<char>::length(cstr) == 2);
    return 0;
}

int main() {}
```


But this compiles fine:
```
#include <string>
static constexpr char cstr[3] = {'1', '2', '\0'};

constexpr int foobar() {    
    return 0;
}

int main() { static_assert(std::char_traits<char>::length(cstr) == 2); }
```

As well as this:
```
#include <string>
static constexpr char cstr[3] = {'1', '2', '\0'};

int foobar() {    
    static_assert(std::char_traits<char>::length(cstr) == 2); 
    return 0;
}

int main() { }
```

Reply via email to