Bug 85319 - std::char_traits<char>::length does not always function in constexpr context
Summary: std::char_traits<char>::length does not always function in constexpr context
Status: RESOLVED DUPLICATE of bug 86524
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2018-04-10 11:10 UTC by Valentine
Modified: 2021-06-25 08:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-05-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Valentine 2018-04-10 11:10:37 UTC
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() { }
```
Comment 1 Jonathan Wakely 2021-06-25 08:32:31 UTC
Fixed in GCC 9.1 by r267341

*** This bug has been marked as a duplicate of bug 86524 ***