[C++ PATCH] Fix main return type checking (PR c++/29735)

Mark Mitchell mark@codesourcery.com
Tue Nov 21 18:15:00 GMT 2006

Jakub Jelinek wrote:
> On Tue, Nov 21, 2006 at 09:34:13AM -0800, Mark Mitchell wrote:
>> Jakub Jelinek wrote:
>>> 2006-11-21  Jakub Jelinek  <jakub@redhat.com>
>>> 	PR c++/29735
>>> 	* decl.c (grokfndecl): Check main's return type after applying
>>> 	attributes, not before.
>> Good analysis.
>> I'm concerned, though; mightn't attributes change parameter types as
>> well?
> There is no attribute that would change that.

Yet. :-)

>> And, I see that we check for explicit specialization before
>> applying attributes; should we worry that we'll not match templates
>> correctly because the types haven't yet been attributified?
> Does check_explicit_specialization ever care about the return type?

This is the kind of reasoning I want to avoid.  Logically, we should
have the type fully set up before we try to check specializations; it
*might* work otherwise, but it might not, and life will be simpler if we
just make sure the declaration is "done" at that point.

> In any case, perhaps swapping the check_explicit_specialization
> and cplus_decl_attributes calls in grokfndecl wouldn't be a bad idea.

My suggestion is to move the attribute stuff right before "if (check <
0)".  (Because the other stuff, like DECL_EXTERNAL, etc., might be
relevant to the attribute handlers.)  Then, move the check for valid
"main" (not just the return type, but all of those checks) after attributes.

In other words:

(1) Set up the declaration flags (DECL_CONTEXT, TREE_PUBLIC, etc.) that
are "basic" properties of the declaration based on C++ itself.

(2) Give the attribute handlers a chance to munge things.

(3) Check validity of the result.

Would you be willing to try that?

Mark Mitchell
(650) 331-3385 x713

More information about the Gcc-patches mailing list