Gah this thread actually is confusing. So let's break it down by lens:
Pre-AI - May mount, may damage the camera. Not officially listed as compatible with the camera. On a D200/300 these will meter if you have an AI-Modified ring. These will not meter on a D40. They work in manual only.
AI, AI-S, AI-P, E series Nikkos, Medial Nikkors, AI Teleconverters, Reflex Nikkors, PC Nikkors, bellows, extention rings - Will mount. None of these will meter. All of these lenses work in manual mode only!
CPU D type Lenses:
AF - Will not autofocus, aperture ring must be set to minimum and the aperture controlled electronically using the camera's selection wheel.
AF-I AF-S, AF-S teleconverters - Full functionality, aperture ring must be set to minimum and aperture controlled electronically using the camera's selection wheel. Autofocus may fail at an effective aperture above f/5.6 (note this anyone thinking of buying Tamron's 18-200)
CPU G type lenses:
AF-S - Full functionality, (no aperture ring to complain about

), Same autofocus deal with larger effective apertures.
Additionally there are 15 lenses listed on page 97 of the manual which may damage the camera if mounted.
Let me know if I missed anything and i'll edit this post so that all the info is kept in one place.