[clang] Should `operator<<>` (note no space within `<<`) be accepted or rejected more clearly?
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I was poking around a CUDA support issue when Lexer would merge two consecutive `<<<` in `operator<<<>` into a single token and fail ([PR](https://github.com/llvm/llvm-project/pull/218384) ) then I realized that you can also do
```c++
struct bar {};
template
void operator<(T, T);
template <>
void operator<<>(bar, bar);
```
which is currently rejected by clang https://godbolt.org/z/17he6rqM8 and many others unless a space is put between `<<` in the operator's specialization. Whereas it was kind of obvious to fix for CUDA since `<<<` is very specific and cannot go after `operator`, `<<` case is slightly more difficult since `operator<<` is also a valid operator. Right now the error emitted is not fun and doesn't suggest putting a space between `<<` which I think would be helpful at least but I'm also curious whether it deserves any attention from the language perspective similarly to https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1699.html .
Contributor guide
Research direction
Start with the Lexer behavior described in PR 218384 and reproduce the operator<<> example using the linked Godbolt case. Determine whether clang should accept the spelling or improve the rejection diagnostic, including a suggestion to add a space, and compare the language discussion in WG21 paper N1699. Done means the behavior and diagnostic are covered by an appropriate clang test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100