In Mac OS, new version of gcc can be installed by macports. After installation, both the new version and old version exist, but the older version is the default compiler. To use the new gcc, we need to change the symlink in /opt/local/bin/gcc by using port select. You can see available version using port select --list gcc. Anything listed with mp- as prefix refers to MacPorts' own port, gcc42 and llvm-gcc42 refer to the compilers shipped with Xcode by Apple.
Example from my system:
$ port select --list gcc
Available versions for gcc:
mp-gcc48
none (active)
$ sudo port select --set gcc mp-gcc48
Password:
Selecting 'mp-gcc48' for 'gcc' succeeded. 'mp-gcc48' is now active.
After that, either open a new terminal window or issue hash -r to make bash recognize the change.