[cfe-commits] [commit-on-approval] Semantic checking for main()

Eli Friedman eli.friedman at gmail.com
Fri Jul 24 19:21:50 PDT 2009


On Fri, Jul 24, 2009 at 5:38 PM, John McCall<rjmccall at apple.com> wrote:
> This ended up taking a little longer than expected because of places that
> exceed the spec.
>
> Most of my diagnostics end up pointing to the 'main' symbol itself, rather
> than to types, because we don't seem to propagate source locations for types
> very reliably.  I also wanted to implement more fixits, but again, no source
> range information (and that's hard for C types anyway).

+  // C++ [basic.start.main]p3:  A program that declares main to be inline
+  //   or static is ill-formed.
+  // This is not an error in C, but we can warn about it.

Declaring main inline is illegal per C99 6.7.4p4.

I'm not sure what happens with static in C99, since nothing is stated
about it; my instinct is that "static int main(float x) {return x;}"
doesn't count as a declaration of "main"; if it were, you could have
multiple definitions of main without otherwise violating any
constraints.

+      if (const PointerType* PT = AT->getAsPointerType()) {
+        QualType ET = PT->getPointeeType();
+        ET.removeConst();
+        if (!ET.getCVRQualifiers() && (PT = ET->getAsPointerType())) {

I think this allows some cases involving ExtQualType which it
shouldn't.  Not really a serious issue, though.

+        }else mismatch = true;
+      }else mismatch = true;
+    }else mismatch = true;

This is kind of ugly; it might be better to initialize mismatch to true.

Otherwise, it looks fine.

-Eli




More information about the cfe-commits mailing list