[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

NagaChaitanya Vellanki via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 8 01:57:16 PDT 2023


chaitanyav added a comment.

output for testcases mentioned in https://github.com/llvm/llvm-project/issues/61943

  test.cpp:6:30: warning: overloaded operator << has higher precedence than comparison operator [-Woverloaded-shift-op-parentheses]
      std::cout << "Test" << a == 5 ? 1 : 0;
      ~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
  test.cpp:6:25: note: place parentheses around the '<<' expression to silence this warning
      std::cout << "Test" << a == 5 ? 1 : 0;
                          ^
      (                       )
  test.cpp:6:30: note: place parentheses around comparison expression to evaluate it first
      std::cout << "Test" << a == 5 ? 1 : 0;
                               ^
                             (     )
  test.cpp:6:30: error: invalid operands to binary expression ('ostream' and 'int')
      std::cout << "Test" << a == 5 ? 1 : 0;
      ~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
  test.cpp:7:30: warning: operator '?:' has lower precedence than '<<'; '<<' will be evaluated first [-Wparentheses]
      std::cout << "Test" << a ? 1 : 0;
      ~~~~~~~~~~~~~~~~~~~~~~~~ ^
  test.cpp:7:30: note: place parentheses around the '<<' expression to silence this warning
      std::cout << "Test" << a ? 1 : 0;
                               ^
      (                       )
  test.cpp:7:30: note: place parentheses around the '?:' expression to evaluate it first
      std::cout << "Test" << a ? 1 : 0;
                               ^
                             (        )
  test.cpp:8:49: warning: operator '?:' has lower precedence than '<<'; '<<' will be evaluated first [-Wparentheses]
      std::cout << "Test" << static_cast<bool>(a) ? 1 : 0;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
  test.cpp:8:49: note: place parentheses around the '<<' expression to silence this warning
      std::cout << "Test" << static_cast<bool>(a) ? 1 : 0;
                                                  ^
      (                                          )
  test.cpp:8:49: note: place parentheses around the '?:' expression to evaluate it first
      std::cout << "Test" << static_cast<bool>(a) ? 1 : 0;
                                                  ^

@aaron.ballman Please review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844



More information about the cfe-commits mailing list