[PATCH] D41368: [libc++] Ignore bogus tautologic comparison warnings

Shoaib Meenai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 18 15:07:25 PST 2017


smeenai created this revision.
smeenai added reviewers: EricWF, mclow.lists.
Herald added a subscriber: cfe-commits.

clang 6 has a new diagnostic -Wtautological-constant-compare, which
fires for the code in question when int and long have the same size (for
example, when compiling for a 32-bit target, or for Windows 64-bit). The
warning is somewhat bogus here, since the code is only tautological on


Repository:
  rCXX libc++

https://reviews.llvm.org/D41368

Files:
  include/istream
  src/string.cpp


Index: src/string.cpp
===================================================================
--- src/string.cpp
+++ src/string.cpp
@@ -80,6 +80,11 @@
 V
 as_integer(const string& func, const S& s, size_t* idx, int base);
 
+#if __clang_major__ >= 6
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtautological-constant-compare"
+#endif
+
 // string
 template<>
 inline
@@ -93,6 +98,10 @@
     return static_cast<int>(r);
 }
 
+#if __clang_major__ >= 6
+#pragma clang diagnostic pop
+#endif
+
 template<>
 inline
 long
@@ -125,6 +134,11 @@
     return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
 }
 
+#if __clang_major__ >= 6
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtautological-constant-compare"
+#endif
+
 // wstring
 template<>
 inline
@@ -138,6 +152,10 @@
     return static_cast<int>(r);
 }
 
+#if __clang_major__ >= 6
+#pragma clang diagnostic pop
+#endif
+
 template<>
 inline
 long
Index: include/istream
===================================================================
--- include/istream
+++ include/istream
@@ -695,6 +695,11 @@
     return *this;
 }
 
+#if __clang_major__ >= 6
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtautological-constant-compare"
+#endif
+
 template <class _CharT, class _Traits>
 basic_istream<_CharT, _Traits>&
 basic_istream<_CharT, _Traits>::operator>>(int& __n)
@@ -735,6 +740,10 @@
     return *this;
 }
 
+#if __clang_major__ >= 6
+#pragma clang diagnostic pop
+#endif // __clang__
+
 template<class _CharT, class _Traits>
 basic_istream<_CharT, _Traits>&
 operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41368.127415.patch
Type: text/x-patch
Size: 1659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171218/cfa304ca/attachment.bin>


More information about the cfe-commits mailing list