Grammar of a C++ Translation Unit

My understanding, for a long time now, was that a C++ translation unit, after the preprocessor has run, is a sequence of declarations (let me remind that any definition is also a declaration).

Many people have argued with this statement but no one has ever given a counterexample. But I myself found this example which troubles me:

int x;       //declaration

;            // ??? EMPTY DECLARATION?

int main()   //dec
{            //la
}            //ration

This compiles fine with MSVC and online comeau. I know the standard defines an empty statement but I never heard of an empty declaration. So, I see three options:

  • My understanding is correct and the standard defines an empty declaration
  • My understanding is correct but the standard doesn't define empty declarations and the above translation is ill-formed
  • My understanding is incorrect, i.e. a C++ TU is not a sequence of declarations

Please help me dissolve my doubts. Thanks

9
задан Armen Tsirunyan 2 December 2010 в 12:58
поделиться