I have been put on a task to upgrade and build 32bit and 64bit libraries for software developers to use. I need to install GCC version 4.7.1 with 64bit support on the Solaris x86 machine I'm using for my user account only so as to not modify the system as a whole.
Download source from
configure with prefix=/home/myname/gccfolder
You may find it just as easy to have your own Solaris host. Just install Solaris X86 into VirtualBox and then you have your own. If the purpose is development and test as in your case then there's no license cost to use Solaris.
Using a package repository avoids the hassle of building yourself and managing dependencies, wondering if you have 64bit support, etc. The downside is that you need to have superuser privileges to install the packages which is why I suggest that you have your own private (virtual) Solaris host.
Install Solaris 11.2 Beta on it. Doesn't matter for your purpose that it is a beta (I'm using it and haven't been able to break it in any way). The reason why I propose to use that version is that the package repository for that version gives a choice of many different versions of GCC (4.5, 4.7 and 4.8). Do you have a need for specifically v4.7.1 or would v4.7.3 also be ok?
If you don't want to use a beta version of Solaris then you can use Solaris 11.1 but that will only give you GCC v3.4.3 or GCC v.4.5.2 from the package repository which doesn't seem to be what you want.
Also see this link on unix.stackexchange.com for how to properly set up a Solaris development host using by-the-book methods.