I checked this, the logic is as follows. The following
suffixes are mapped to the equivalent driver flags:
{"clang", nullptr}
{"clang++", "--driver-mode=g++"}
{"clang-c++", "--driver-mode=g++"}
{"clang-cc", nullptr}
{"clang-cpp", "--driver-mode=cpp"}
{"clang-g++", "--driver-mode=g++"}
{"clang-gcc", nullptr}
{"clang-cl", "--driver-mode=cl"}
{"cc", nullptr}
{"cpp", "--driver-mode=cpp"}
{"cl", "--driver-mode=cl"}
{"++", "--driver-mode=g++"}
{"flang", "--driver-mode=flang"}
`clang++-x` matches none of these. Then the same logic is applied to the name with any of "0123456789." trimmed from the right. Still no match. Then the trailing `-component` is stripped, and `clang++` matches.
It works by chance...
See https://github.com/llvm/llvm-project/blob/c22b110612600b0d0a... and https://github.com/llvm/llvm-project/blob/c22b110612600b0d0a...
TIL: if you symlink ++ -> clang it works as a compiler in C++ mode.