aaron.ballman added a comment.

In D147844#4278384 <https://reviews.llvm.org/D147844#4278384>, @chaitanyav 
wrote:

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

I would expect to get the same diagnostic with either `operator int()` or 
`operator bool()` as the precedence is the same either way. I think what might 
be happening here is that `ExprLooksBoolean` is getting tricked into thinking 
the expression isn't boolean when it actually is (I think this might be the 
`FIXME` comment in that function needing to be addressed).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to