Issue 173985
Summary [clang] erroneously does not accept `$` as user-defined literal operator name
Labels clang
Assignees
Reporter toughengineer
    While trying to compile this code:

```c++
#include <iostream>

auto operator ""_$(const char *p, size_t n) {
  return std::string(p, n);
}

int main() {
  std::cout << "xxx"_$;
}
```

Clang (current trunk) gives an error:
```
error: 'operator""_' cannot be the name of a variable or data member
```

<details><summary>Click/tap to see the whole output.</summary>

```
<source>:3:6: error: 'operator""_' cannot be the name of a variable or data member
    3 | auto operator ""_$(const char *p, size_t n) {
      |      ^
<source>:3:18: error: expected ';' after top level declarator
    3 | auto operator ""_$(const char *p, size_t n) {
 |                  ^
      |                  ;
<source>:8:21: error: no matching literal operator for call to 'operator""_' with arguments of types 'const char *' and '__size_t' (aka 'unsigned long'), and no matching literal operator template
    8 |   std::cout << "xxx"_$;
      | ^
3 errors generated.
```
</details>

This issue reproduces since Clang 3.2 (as far as I can tell, in 3.1 it also does not work properly).

Latest versions of GCC and MSVC correctly compile the code.

Reproduction: https://godbolt.org/z/G4E7n1Gdq
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to