apt install g++-10 installs clang-10 instead of g++-10

The issue here is that the default Ubuntu 18.04 repositories don't contain g++-10 (but do contain clang-10)

On 18.04, if apt fails to match an exact package name, it expands the name as a regular expression1. In this context, the + character means "one or more of the preceding character" so g++-10 matches clang-10 (it's just coincidental that they're both compilers).

If you want gcc-10 / g++-10 on 18.04 you can do so by adding the toolchain-r PPA to your repositories:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt install g++-10

See also

  • How do I use the latest GCC on Ubuntu?

Notes:

  1. it no longer does that - see for example Problem using wildcard with apt

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt install g++-10