Update: Download 14.1 beta 3 or higher to resolve the issue. Otherwise, read below.
The issue is with XCode 14.0 version, which I have tested and confirmed.
Downgrade your command line tools version to 13.4 and it will be resolved.
First download command line tools from the apple developers site and install it: https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_13.4/Command_Line_Tools_for_Xcode_13.4.dmg
You can change the version using the following command:
sudo xcode-select --switch /Library/Developer/CommandLineTools
To check the version of currently selected xcode command line tools, use the following command:
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
Make sure it is 13.4.
There are multiple GitHub discussions around this:
https://github.com/iains/gcc-12-branch/issues/6
https://github.com/Homebrew/discussions/discussions/3659