IQ tests were first developped because it seemed obvious not all students performed equally. On average a student that is good in a given discipline will also tend to do well in other unrelated disciplines. On average is the keyword here, outliers exist.
I think gifted students can easily tell what side of the curve they're on, even though they might not want to acknowledge it. It is not even avout the grades, because gifted students also often learn early on that they can get away by doing the minimum amount of work and still get passing grades. So they're not necessarily top of classes.
Gifted students get told they're fast learner all the time, and they notice how everyone else seem to be progressing in slow motion. They know.
I think it gets harder to self-evaluate the closer you are to the average, since most of your peers will be more or less just as intelligent as you. Then, the dullest you are, and the less you can identify competense and the more likely you are to be over-confident.
I think in the end, most people will end up believing they're above average because we tend to notice dumb people a lot. Ironically it is probably students who are just slightly above average who will have the most self-doubts, because they feel different from their peers, yet they can probably tell more gifted students are around.
Source: 50% my ass, 50% being surrounded by incredibly smart people who shared their personal experiences with me.