First remove all clang versions.
sudo apt --purge remove clang*
Now its time to figure out which version of clang do you need.
But according to Building on Linux:Clang documentation by Unreal, you have to know what version of clang you need to install, apparently dependent on your OS distribution.
The link directly takes you to the Clang Section
For example if you have Ubuntu 16.04 or newer, use clang-3.8. Else using 4.0.1 should be ok imo
Now time to install and configure clang. For this post, I am assuming that you use 16.04+. So I’ll focus on clang-3.8
Change your version accordingly
sudo apt-get install clang-3.8
This will install clang-3.8 on your system. If you want any other versions, depending on your distro,
sudo apt-get install clang- *<don't press Enter yet>*
TAB a few times, this should list all possible versions of clang, that can be installed.
I suggest you install 3.8 for Ubuntu 16.04+ cause that is advised to use in the Documentation
So if you installed clang-3.8, we still need to configure it as the default clang provider.
Replace 3.8 with your version of clang, if required. Also if you installed 4.0.1 instead of 4.0, I mean 3 digits instead of 2, then make sure to use
x.y.z version name, so as to avoid any further problems in the future
First comes clang++
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100
Now do the same thing with clang
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100
Now check which version of clang is installed
This should fix the problem for clang and now you should be able to compile UE4.