[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
Tue Apr 18 12:45:02 PDT 2023


chaitanyav added a comment.

@aaron.ballman am looking into this. If i change it back to
 `operation int();`
and add
`Stream& operator<<(bool)`

I get

`
-

error: 'warning' diagnostics expected but not seen:

  File /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp Line 68: operator '?:' has lower precedence than '<<'

error: 'note' diagnostics expected but not seen:

  File /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp Line 68: place parentheses around the '<<' expression to silence this warning
  File /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp Line 68: place parentheses around the '?:' expression to evaluate it first

3 errors generated.

-

`

But it works correctly with std::cout

`
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;
                           ^
                         (        )

`


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