chaitanyav updated this revision to Diff 517268.
chaitanyav added a comment.

Disable precedence conditional warning by default; Revert changes to test files


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147844/new/

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/zvector.c
  clang/test/Sema/zvector2.c
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/src/filesystem/operations.cpp
  libcxx/src/locale.cpp
  libcxx/src/memory_resource.cpp
  libcxx/src/ryu/d2fixed.cpp
  libcxx/src/ryu/f2s.cpp
  libcxxabi/src/cxa_default_handlers.cpp
  libcxxabi/src/cxa_demangle.cpp
  libcxxabi/src/cxa_exception.cpp
  libcxxabi/src/cxa_personality.cpp
  libcxxabi/src/demangle/ItaniumDemangle.h

Index: libcxxabi/src/demangle/ItaniumDemangle.h
===================================================================
--- libcxxabi/src/demangle/ItaniumDemangle.h
+++ libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1306,7 +1306,7 @@
   const Node *getSyntaxNode(OutputBuffer &OB) const override {
     initializePackExpansion(OB);
     size_t Idx = OB.CurrentPackIndex;
-    return Idx < Data.size() ? Data[Idx]->getSyntaxNode(OB) : this;
+    return (Idx < Data.size()) ? Data[Idx]->getSyntaxNode(OB) : this;
   }
 
   void printLeft(OutputBuffer &OB) const override {
@@ -2499,7 +2499,7 @@
     return false;
   }
 
-  char consume() { return First != Last ? *First++ : '\0'; }
+  char consume() { return (First != Last) ? *First++ : '\0'; }
 
   char look(unsigned Lookahead = 0) const {
     if (static_cast<size_t>(Last - First) <= Lookahead)
Index: libcxxabi/src/cxa_personality.cpp
===================================================================
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
             if (actionEntry == 0)
             {
                 // Found a cleanup
-                results.reason = actions & _UA_SEARCH_PHASE
-                                     ? _URC_CONTINUE_UNWIND
-                                     : _URC_HANDLER_FOUND;
+                results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
                 return;
             }
             // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
                     // End of action list. If this is phase 2 and we have found
                     // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
                     // otherwise return _URC_CONTINUE_UNWIND.
-                    results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
-                                         ? _URC_HANDLER_FOUND
-                                         : _URC_CONTINUE_UNWIND;
+                    results.reason =
+                        (hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
                     return;
                 }
                 // Go to next action
@@ -1243,10 +1240,9 @@
             {
                 const __shim_type_info* excpType =
                     static_cast<const __shim_type_info*>(new_exception_header->exceptionType);
-                adjustedPtr =
-                    __getExceptionClass(&new_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-                        ((__cxa_dependent_exception*)new_exception_header)->primaryException :
-                        new_exception_header + 1;
+                adjustedPtr = (__getExceptionClass(&new_exception_header->unwindHeader) == kOurDependentExceptionClass)
+                                  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+                                  : new_exception_header + 1;
                 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
                                               excpType, adjustedPtr,
                                               unwind_exception, base))
Index: libcxxabi/src/cxa_exception.cpp
===================================================================
--- libcxxabi/src/cxa_exception.cpp
+++ libcxxabi/src/cxa_exception.cpp
@@ -455,8 +455,8 @@
     if (native_exception)
     {
         // Increment the handler count, removing the flag about being rethrown
-        exception_header->handlerCount = exception_header->handlerCount < 0 ?
-            -exception_header->handlerCount + 1 : exception_header->handlerCount + 1;
+        exception_header->handlerCount = (exception_header->handlerCount < 0) ? -exception_header->handlerCount + 1
+                                                                              : exception_header->handlerCount + 1;
         //  place the exception on the top of the stack if it's not already
         //    there by a previous rethrow
         if (exception_header != globals->caughtExceptions)
Index: libcxxabi/src/cxa_demangle.cpp
===================================================================
--- libcxxabi/src/cxa_demangle.cpp
+++ libcxxabi/src/cxa_demangle.cpp
@@ -402,6 +402,6 @@
 
   if (Status)
     *Status = InternalStatus;
-  return InternalStatus == demangle_success ? Buf : nullptr;
+  return (InternalStatus == demangle_success) ? Buf : nullptr;
 }
 }  // __cxxabiv1
Index: libcxxabi/src/cxa_default_handlers.cpp
===================================================================
--- libcxxabi/src/cxa_default_handlers.cpp
+++ libcxxabi/src/cxa_default_handlers.cpp
@@ -55,10 +55,9 @@
     if (!__isOurExceptionClass(unwind_exception))
         abort_message("terminating due to %s foreign exception", cause);
 
-    void* thrown_object =
-        __getExceptionClass(unwind_exception) == kOurDependentExceptionClass ?
-            ((__cxa_dependent_exception*)exception_header)->primaryException :
-            exception_header + 1;
+    void* thrown_object = (__getExceptionClass(unwind_exception) == kOurDependentExceptionClass)
+                              ? ((__cxa_dependent_exception*)exception_header)->primaryException
+                              : exception_header + 1;
     const __shim_type_info* thrown_type =
         static_cast<const __shim_type_info*>(exception_header->exceptionType);
     auto name = demangle(thrown_type->name());
Index: libcxx/src/ryu/f2s.cpp
===================================================================
--- libcxx/src/ryu/f2s.cpp
+++ libcxx/src/ryu/f2s.cpp
@@ -393,7 +393,7 @@
     _LIBCPP_ASSERT(_Data[_Idx] == 0, "");
   }
 
-  const uint32_t _Data_olength = _Data[0] >= 1000000000 ? 10 : __decimalLength9(_Data[0]);
+  const uint32_t _Data_olength = (_Data[0] >= 1000000000) ? 10 : __decimalLength9(_Data[0]);
   const uint32_t _Total_fixed_length = _Data_olength + 9 * _Filled_blocks;
 
   if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
Index: libcxx/src/ryu/d2fixed.cpp
===================================================================
--- libcxx/src/ryu/d2fixed.cpp
+++ libcxx/src/ryu/d2fixed.cpp
@@ -272,7 +272,7 @@
 
   bool __nonzero = false;
   if (__e2 >= -52) {
-    const uint32_t __idx = __e2 < 0 ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
+    const uint32_t __idx = (__e2 < 0) ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
     const uint32_t __p10bits = __pow10BitsForIndex(__idx);
     const int32_t __len = static_cast<int32_t>(__lengthForIndex(__idx));
     for (int32_t __i = __len - 1; __i >= 0; --__i) {
@@ -468,7 +468,7 @@
   uint32_t __availableDigits = 0;
   int32_t __exp = 0;
   if (__e2 >= -52) {
-    const uint32_t __idx = __e2 < 0 ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
+    const uint32_t __idx = (__e2 < 0) ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
     const uint32_t __p10bits = __pow10BitsForIndex(__idx);
     const int32_t __len = static_cast<int32_t>(__lengthForIndex(__idx));
     for (int32_t __i = __len - 1; __i >= 0; --__i) {
@@ -640,7 +640,7 @@
     _Sign_character = '+';
   }
 
-  const int _Exponent_part_length = __exp >= 100
+  const int _Exponent_part_length = (__exp >= 100)
     ? 5 // "e+NNN"
     : 4; // "e+NN"
 
Index: libcxx/src/memory_resource.cpp
===================================================================
--- libcxx/src/memory_resource.cpp
+++ libcxx/src/memory_resource.cpp
@@ -361,8 +361,8 @@
     }
     void* result = __fixed_pools_[i].__try_allocate_from_vacancies();
     if (result == nullptr) {
-      auto min = [](size_t a, size_t b) { return a < b ? a : b; };
-      auto max = [](size_t a, size_t b) { return a < b ? b : a; };
+      auto min = [](size_t a, size_t b) { return (a < b) ? a : b; };
+      auto max = [](size_t a, size_t b) { return (a < b) ? b : a; };
 
       size_t prev_chunk_size_in_bytes  = __fixed_pools_[i].__previous_chunk_size_in_bytes();
       size_t prev_chunk_size_in_blocks = prev_chunk_size_in_bytes >> __log2_pool_block_size(i);
Index: libcxx/src/locale.cpp
===================================================================
--- libcxx/src/locale.cpp
+++ libcxx/src/locale.cpp
@@ -1673,7 +1673,7 @@
                     break;
         }
     }
-    return frm_nxt == frm_end ? ok : partial;
+    return (frm_nxt == frm_end) ? ok : partial;
 }
 
 codecvt<wchar_t, char, mbstate_t>::result
@@ -1718,7 +1718,7 @@
                 }
             }
             frm_nxt = frm;
-            return frm_nxt == frm_end ? ok : partial;
+            return (frm_nxt == frm_end) ? ok : partial;
         }
         if (n == size_t(-1))
             return error;
@@ -1739,7 +1739,7 @@
                     break;
         }
     }
-    return frm_nxt == frm_end ? ok : partial;
+    return (frm_nxt == frm_end) ? ok : partial;
 }
 
 codecvt<wchar_t, char, mbstate_t>::result
@@ -1806,7 +1806,7 @@
 int
 codecvt<wchar_t, char, mbstate_t>::do_max_length() const noexcept
 {
-    return __l_ == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l_));
+    return (__l_ == 0) ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l_));
 }
 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
@@ -2097,7 +2097,7 @@
             return codecvt_base::error;
         }
     }
-    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+    return (frm_nxt < frm_end) ? codecvt_base::partial : codecvt_base::ok;
 }
 
 static
@@ -2218,7 +2218,7 @@
             return codecvt_base::error;
         }
     }
-    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+    return (frm_nxt < frm_end) ? codecvt_base::partial : codecvt_base::ok;
 }
 
 static
@@ -2488,7 +2488,7 @@
             return codecvt_base::error;
         }
     }
-    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+    return (frm_nxt < frm_end) ? codecvt_base::partial : codecvt_base::ok;
 }
 
 static
@@ -2713,7 +2713,7 @@
             return codecvt_base::error;
         }
     }
-    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+    return (frm_nxt < frm_end) ? codecvt_base::partial : codecvt_base::ok;
 }
 
 static
@@ -2872,7 +2872,7 @@
             frm_nxt += 4;
         }
     }
-    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+    return (frm_nxt < frm_end) ? codecvt_base::partial : codecvt_base::ok;
 }
 
 static
@@ -3004,7 +3004,7 @@
             frm_nxt += 4;
         }
     }
-    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+    return (frm_nxt < frm_end) ? codecvt_base::partial : codecvt_base::ok;
 }
 
 static
@@ -3098,7 +3098,7 @@
         *to_nxt = c1;
         frm_nxt += 2;
     }
-    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+    return (frm_nxt < frm_end) ? codecvt_base::partial : codecvt_base::ok;
 }
 
 static
@@ -3172,7 +3172,7 @@
         *to_nxt = c1;
         frm_nxt += 2;
     }
-    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+    return (frm_nxt < frm_end) ? codecvt_base::partial : codecvt_base::ok;
 }
 
 static
Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ libcxx/src/filesystem/operations.cpp
@@ -116,7 +116,7 @@
   PosPtr peek() const noexcept {
     auto TkEnd = getNextTokenStartPos();
     auto End = getAfterBack();
-    return TkEnd == End ? nullptr : TkEnd;
+    return (TkEnd == End) ? nullptr : TkEnd;
   }
 
   void increment() noexcept {
@@ -311,7 +311,7 @@
   PosPtr consumeAllSeparators(PosPtr P, PosPtr End) const noexcept {
     if (P == nullptr || P == End || !isSeparator(*P))
       return nullptr;
-    const int Inc = P < End ? 1 : -1;
+    const int Inc = (P < End) ? 1 : -1;
     P += Inc;
     while (P != End && isSeparator(*P))
       P += Inc;
@@ -337,7 +337,7 @@
     PosPtr Start = P;
     if (P == nullptr || P == End || isSeparator(*P))
       return nullptr;
-    const int Inc = P < End ? 1 : -1;
+    const int Inc = (P < End) ? 1 : -1;
     P += Inc;
     while (P != End && !isSeparator(*P))
       P += Inc;
Index: libcxx/include/strstream
===================================================================
--- libcxx/include/strstream
+++ libcxx/include/strstream
@@ -300,7 +300,7 @@
     _LIBCPP_INLINE_VISIBILITY
     ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
         : ostream(&__sb_),
-          __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
+          __sb_(__s, __n, __s + ((__mode & ios::app) ? _VSTD::strlen(__s) : 0))
         {}
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -360,7 +360,7 @@
     _LIBCPP_INLINE_VISIBILITY
     strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
         : iostream(&__sb_),
-          __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
+          __sb_(__s, __n, __s + ((__mode & ios::app) ? _VSTD::strlen(__s) : 0))
         {}
 
 #ifndef _LIBCPP_CXX03_LANG
Index: libcxx/include/__chrono/duration.h
===================================================================
--- libcxx/include/__chrono/duration.h
+++ libcxx/include/__chrono/duration.h
@@ -194,7 +194,7 @@
         return __lower;
     if (__lower_diff > __upper_diff)
         return __upper;
-    return __lower.count() & 1 ? __upper : __lower;
+    return (__lower.count() & 1) ? __upper : __lower;
 }
 #endif
 
Index: clang/test/Sema/zvector2.c
===================================================================
--- clang/test/Sema/zvector2.c
+++ clang/test/Sema/zvector2.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple s390x-linux-gnu -fzvector -target-cpu z14 \
-// RUN:  -flax-vector-conversions=none -W -Wall -Wconversion \
+// RUN:  -flax-vector-conversions=none -W -Wall -Wno-parentheses -Wconversion \
 // RUN:  -Werror -fsyntax-only -verify %s
 
 vector signed char sc, sc2;
Index: clang/test/Sema/zvector.c
===================================================================
--- clang/test/Sema/zvector.c
+++ clang/test/Sema/zvector.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple s390x-linux-gnu -fzvector \
 // RUN:  -flax-vector-conversions=none -W -Wall -Wconversion \
-// RUN:  -Werror -fsyntax-only -verify %s
+// RUN:  -Werror -fsyntax-only -Wno-parentheses -verify %s
 
 vector signed char sc, sc2;
 vector unsigned char uc, uc2;
Index: clang/test/Sema/sizeless-1.c
===================================================================
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -Wno-comment -Wno-strict-prototypes -triple arm64-linux-gnu -target-feature +sve -std=c90 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -Wno-strict-prototypes -triple arm64-linux-gnu -target-feature +sve -std=c11 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -Wno-strict-prototypes -triple arm64-linux-gnu -target-feature +sve -std=gnu11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -Wno-parentheses -Wno-comment -Wno-strict-prototypes -triple arm64-linux-gnu -target-feature +sve -std=c90 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -Wno-parentheses -Wno-strict-prototypes -triple arm64-linux-gnu -target-feature +sve -std=c11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -Wno-parentheses -Wno-strict-prototypes -triple arm64-linux-gnu -target-feature +sve -std=gnu11 %s
 
 typedef __SVInt8_t svint8_t;
 typedef __SVInt16_t svint16_t;
Index: clang/test/Sema/parentheses.cpp
===================================================================
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -38,7 +38,7 @@
   Stream &operator>>(const char*);
 };
 
-void f(Stream& s, bool b) {
+void f(Stream& s, bool b, int x) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
                                   // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
                                   // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
@@ -62,6 +62,33 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
+
+  void(s << "Test" << x ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+                                         // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+                                        // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:24}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:23-[[@LINE-5]]:23}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:40-[[@LINE-6]]:40}:")"
+
+  void(s << x == 1 ? "foo": "bar"); //expected-warning {{overloaded operator << has higher precedence than comparison operator}} \
+                                    //expected-warning {{operator '?:' has lower precedence than '=='}} \
+                                    //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+                                    //expected-note {{place parentheses around the '?:' expression to evaluate it first}} 
+                                    //expected-note {{place parentheses around the '==' expression to silence this warning}} \
+                                    //expected-note {{place parentheses around comparison expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:15-[[@LINE-4]]:15}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
+
+  void(s << static_cast<bool>(x) ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+                                                  //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+                                                 //expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:49-[[@LINE-6]]:49}:")"
 }
 
 struct S {
Index: clang/test/Sema/parentheses.c
===================================================================
--- clang/test/Sema/parentheses.c
+++ clang/test/Sema/parentheses.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
 // RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
 // RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
@@ -84,14 +84,14 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:24-[[@LINE-6]]:24}:")"
 
-  (void)(x % 2 ? 1 : 2); // no warning
+  (void)(x % 2 ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '%'}} expected-note 2{{place parenthese}}
 
   (void)(x + p ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}
-  (void)(p + x ? 1 : 2); // no warning
+  (void)(p + x ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}
 
   (void)(p + b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}
 
-  (void)(x + y > 0 ? 1 : 2); // no warning
+  (void)(x + y > 0 ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '>'}} expected-note 2{{place parentheses}}
   (void)(x + (y > 0) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}
 
   (void)(b ? 0xf0 : 0x10 | b ? 0x5 : 0x2); // expected-warning {{operator '?:' has lower precedence than '|'}} expected-note 2{{place parentheses}}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9238,7 +9238,8 @@
 
   // Built-in binary operator.
   if (BinaryOperator *OP = dyn_cast<BinaryOperator>(E)) {
-    if (IsArithmeticOp(OP->getOpcode())) {
+    if (IsArithmeticOp(OP->getOpcode()) ||
+        BinaryOperator::isComparisonOp(OP->getOpcode())) {
       *Opcode = OP->getOpcode();
       *RHSExprs = OP->getRHS();
       return true;
@@ -9282,6 +9283,8 @@
     return OP->getOpcode() == UO_LNot;
   if (E->getType()->isPointerType())
     return true;
+  if (E->getType()->isIntegerType())
+    return true;
   // FIXME: What about overloaded operator calls returning "unspecified boolean
   // type"s (commonly pointer-to-members)?
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6628,7 +6628,7 @@
 
 def warn_precedence_conditional : Warning<
   "operator '?:' has lower precedence than '%0'; '%0' will be evaluated first">,
-  InGroup<Parentheses>;
+  InGroup<Parentheses>, DefaultIgnore;
 def warn_precedence_bitwise_conditional : Warning<
   "operator '?:' has lower precedence than '%0'; '%0' will be evaluated first">,
   InGroup<BitwiseConditionalParentheses>;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -325,6 +325,9 @@
   member pointer as an invalid expression.
 - Fix crash when member function contains invalid default argument.
   (`#62122 <https://github.com/llvm/llvm-project/issues/62122>`_)
+- Print diagnostic warning about precedence when integer expression is used
+  without parentheses in an conditional operator expression
+  (`#61943 <https://github.com/llvm/llvm-project/issues/61943>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to