From 728b5dfaf9ea34ae3e0a273975cd1b6ac0971ab8 Mon Sep 17 00:00:00 2001 From: dim Date: Tue, 19 Dec 2017 11:44:24 +0000 Subject: [PATCH] MFC r326880: Pull in r320755 from upstream clang trunk (by me): Don't trigger -Wuser-defined-literals for system headers Summary: In D41064, I proposed adding `#pragma clang diagnostic ignored "-Wuser-defined-literals"` to some of libc++'s headers, since these warnings are now triggered by clang's new `-std=gnu++14` default: $ cat test.cpp #include $ 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 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 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 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 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 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 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 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 operator "" s( const char32_t *__str, size_t __len ) ^ 8 warnings generated. Both @aaron.ballman and @mclow.lists felt that adding this workaround to the libc++ headers was the wrong way, and it should be fixed in clang instead. Here is a proposal to do just that. I verified that this suppresses the warning, even when -Wsystem-headers is used, and that the warning is still emitted for a declaration outside of system headers. Reviewers: aaron.ballman, mclow.lists, rsmith Reviewed By: aaron.ballman Subscribers: mclow.lists, aaron.ballman, andrew, emaste, cfe-commits Differential Revision: https://reviews.llvm.org/D41080 This will allow to compile some of the libc++ headers in C++14 mode (which is the default for gcc 6 and higher, and will be the default for clang 6.0.0 and higher), with -Wsystem-headers and -Werror enabled. Reported by: andrew git-svn-id: svn://svn.freebsd.org/base/stable/9@326976 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- contrib/llvm/tools/clang/lib/Sema/SemaDeclCXX.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/llvm/tools/clang/lib/Sema/SemaDeclCXX.cpp b/contrib/llvm/tools/clang/lib/Sema/SemaDeclCXX.cpp index 6b3400ada..f75cc9779 100644 --- a/contrib/llvm/tools/clang/lib/Sema/SemaDeclCXX.cpp +++ b/contrib/llvm/tools/clang/lib/Sema/SemaDeclCXX.cpp @@ -10952,7 +10952,8 @@ FinishedParams: StringRef LiteralName = FnDecl->getDeclName().getCXXLiteralIdentifier()->getName(); - if (LiteralName[0] != '_') { + if (LiteralName[0] != '_' && + !getSourceManager().isInSystemHeader(FnDecl->getLocation())) { // C++11 [usrlit.suffix]p1: // Literal suffix identifiers that do not start with an underscore // are reserved for future standardization. -- 2.45.0