This is an archive of the discontinued LLVM Phabricator instance.

Suppress -Wuser-defined-literals for <string> and <string_view>
AbandonedPublic

Authored by dim on Dec 11 2017, 4:37 AM.

Details

Summary

When compiling <string> and/or <string_view> with -Wsystem-headers, in
C++14 or higher mode, clang produces warnings about the literal suffixes
defined in them, e.g.:

$ cat test.cpp
#include <string>

$ clang -std=c++14 -Wsystem-headers -Wall -Wextra -c test.cpp
In file included from test.cpp:1:
In file included from /usr/include/c++/v1/string:470:
/usr/include/c++/v1/string_view:763:29: warning: user-defined literal suffixes not starting with '_' are reserved [-Wuser-defined-literals]
    basic_string_view<char> operator "" sv(const char *__str, size_t __len)
                            ^
/usr/include/c++/v1/string_view:769:32: warning: user-defined literal suffixes not starting with '_' are reserved [-Wuser-defined-literals]
    basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len)
                               ^
/usr/include/c++/v1/string_view:775:33: warning: user-defined literal suffixes not starting with '_' are reserved [-Wuser-defined-literals]
    basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len)
                                ^
/usr/include/c++/v1/string_view:781:33: warning: user-defined literal suffixes not starting with '_' are reserved [-Wuser-defined-literals]
    basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len)
                                ^
In file included from test.cpp:1:
/usr/include/c++/v1/string:4012:24: warning: user-defined literal suffixes not starting with '_' are reserved [-Wuser-defined-literals]
    basic_string<char> operator "" s( const char *__str, size_t __len )
                       ^
/usr/include/c++/v1/string:4018:27: warning: user-defined literal suffixes not starting with '_' are reserved [-Wuser-defined-literals]
    basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
                          ^
/usr/include/c++/v1/string:4024:28: warning: user-defined literal suffixes not starting with '_' are reserved [-Wuser-defined-literals]
    basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
                           ^
/usr/include/c++/v1/string:4030:28: warning: user-defined literal suffixes not starting with '_' are reserved [-Wuser-defined-literals]
    basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
                           ^
8 warnings generated.

Similar to what is done in <exception>, suppress these warnings using
#pragma clang diagnostic.

Event Timeline

dim created this revision.Dec 11 2017, 4:37 AM

I think that it would be more appropriate to fix this in Clang rather than libc++. For instance, we don't want libstdc++ to have to silence our same diagnostic here.

mclow.lists requested changes to this revision.Dec 11 2017, 10:07 AM

I think that it would be more appropriate to fix this in Clang rather than libc++. For instance, we don't want libstdc++ to have to silence our same diagnostic here.

I agree.

This revision now requires changes to proceed.Dec 11 2017, 10:07 AM
dim updated this revision to Diff 126397.Dec 11 2017, 10:11 AM
dim edited edge metadata.

Updated to also include <chrono> and <complex>. I think all cases are
covered now.

dim abandoned this revision.Dec 11 2017, 11:12 AM

Abandoned in favor of D41080.