This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH INSTALLED]: const typedefs part 1/N


On Thu, 2 Aug 2007, Kaveh R. GHAZI wrote:

> On Wed, 1 Aug 2007, Andrew Pinski wrote:
>
> > These sets of patches have caused a lot of warnings to show up while
> > compiling with GCC 3.3.3:
> > ../../gcc/tree.h:4986: warning: duplicate `const'
> >
> > etc.
> > Two reduced testcases come down to:
> > const int a;
> > __typeof(a) const c;
> >
> > and:
> > typedef const int a;
> > a const c;
> >
> > I was wondering if the trunk should be warning or not.  And maybe how
> > to get rid of the warnings for 3.3 building.  I am using 3.3.3 to
> > bootstrap GCC with so it slows down compiling the first stage by a
> > huge amount.
>
> I don't have 3.3.x handy, but I've compiled mainlne with 3.4.6 and I don't
> see these diags.  Neither do they show up during bootstrap in stage2/3.
>
> Also, I don't think your testcase is representative of the actual code
> because it produces a diagnostic with my 3.4.6 and mainline using -W -Wall
> -pedantic, whereas bootstrapping doesn't.  So something is different
> between your testcase and mainline sources.  Maybe it's the code or maybe
> your configure flags differ from mine, I dunno.  Most (all?) of the places
> I used "__typeof() const" should have been on rtx and tree typedefs not
> int.  That may be significant because e.g. tree is union tree_node * so
> the const would be applied to the pointer variable being declared, not the
> union.
>
> Would you please give me a testcase that warns for 3.3.3 but does *not*
> warn for mainline?  Meanwhile I'll build a 3.3.x and see if I can
> reproduce it.

Andrew,

I managed to reproduce this with 3.3.6.  The problem occurs with 3.0
through 3.3.  I verified that it does not occur with 2.95 and prior, or
with 3.4.0 or later.

As I suspected I was also able to verify that your testcase is not
relevant, in that the idiom using "__typeof(foo) const" does not occur
with foo=int.  It only occurs with e.g. tree or rtx.  The reason this is
important is that using an int will pedwarn with all gcc-3.x and 4.x
versions, whereas typedef'ed pointers follow the restricted versioning
pattern I described above.

Furthermore the "__typeof(x) const" code is only used inside
ENABLE_CHECKING guards, so users building a released mainline with 3.0
through 3.3 won't see it.  Only developers (such as yourself) building
stage1 with 3.0 through 3.3 and checking enabled will see extra warns (and
it's just warns not errors, albeit a lot of them).  I think it's important
to describe exactly when the problem occurs because it's limited to a very
specific set of circumstances.

Here is a proper testcase that only fails for 3.0 through 3.3:

	union tree_node;
	typedef union tree_node *tree;

	#define TREE_CHECK(d) __extension__ ({ __typeof (d) const _decl = (d); _decl; })

	void foo (tree foo)
	{
	  tree const t1 = foo;
	  union tree_node *const t2 = foo;
	  tree t3;

	  t3 = TREE_CHECK (t1);
	  t3 = TREE_CHECK (t2);
	}

GCC 3.0 - 3.3 warns for both assignments to t3.  IMHO, it's a bug for gcc
for warn like this, and it was properly fixed in 3.4.0.

I don't know that there is anything here left to fix.  I don't feel that
taking out the const qualifiers constitutes making the code more correct.
If the bogus warnings really bother you there are several options.

1.  Upgrade your bootstrap compiler to 3.4.0 or later.

2.  Configure with checking=release.

3.  If it bothers more people perhaps we could bump the ENABLE_CHECKING
guards to require 3.4 or later.  (Currently checking requires 2.7).


I don't like 3, can you live with #1?

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]