Re: Problem with use of anonymous types

2005-05-07 Thread Andrew Pinski
On May 7, 2005, at 6:40 PM, Gabriel Dos Reis wrote:
"Julian Cummings" <[EMAIL PROTECTED]> writes:
| Hmmm... I just read through the bug reports you cited.  Sounds to me 
like
| this is still somewhat of an open issue, as to whether the compiler 
should
| issue an error in these cases or simply silently discard any 
templated
| function as a possible match for an operation involving an unnamed 
type.  As

You're right, the issue is still open.  I think people should be
careful in closing PRs related to that issue.
I can see the reasoning behind the error but it does not make any
sense to me.
Well let me say I did not close the PR in the first place, and Mark did.
-- Pinski


Re: Problem with use of anonymous types

2005-05-07 Thread Gabriel Dos Reis
"Julian Cummings" <[EMAIL PROTECTED]> writes:

| Hmmm... I just read through the bug reports you cited.  Sounds to me like
| this is still somewhat of an open issue, as to whether the compiler should
| issue an error in these cases or simply silently discard any templated
| function as a possible match for an operation involving an unnamed type.  As

You're right, the issue is still open.  I think people should be
careful in closing PRs related to that issue.  
I can see the reasoning behind the error but it does not make any
sense to me.  

| was pointed out in the discussion, this is a *disastrous* change in the
| standard behavior of gcc because it essentially makes it impossible to
| safely use an unnamed enum type in an arithmetic operation.  There is bound
| to be some template function overload declared in some header file somewhere
| that suddenly makes your code not work.  I am shocked that there is no
| compiler flag made available to restore the previous behavior, especially in
| light of the fact that the disposition of this issue remains unresolved.  I

Please consider filling a PR and expliclty mention the fact that the
issue is under discussion withing the C++ committee.

| have checked several other C++ compilers now (Intel icc 8.1 and IBM xlC 7.0,
| for instance) and they all accept my example.

-- Gaby


Re: Problem with use of anonymous types

2005-05-07 Thread Gabriel Dos Reis
Andrew Pinski <[EMAIL PROTECTED]> writes:

| On May 6, 2005, at 8:09 PM, Julian Cummings wrote:
| 
| > People are reporting trouble compiling blitz with gcc-4.0.0, and the
| > compiler errors are resulting from the use of unnamed enums.  A
| > simple code
| > illustrates the problem:
| >
| >   struct nullType {};
| >   template  inline T operator+(const T& a, nullType) {
| > return a;
| > }
| >   enum named { namedA = 1, namedB = 2 };
| >   enum { unnamedA = 2, unnamedB = 4 };
| >   struct bar {
| > enum { namedC = namedA + namedB,
| >unnamedC = unnamedA + unnamedB };
| >   };
| >   int main() {
| >   }
| >
| > The gcc compiler complains about trying to add unnamedA and unnamedB.
| > Apparently it gets confused by the presence of the operator+
| > overload for
| > the empty struct nullType.  I don't see why the compiler would think
| > that
| > the anonymous enumerators unnamedA or unnamedB would match with type
| > nullType.  Enumerators are supposed to default to integers when used in
| > arithmetic operations such as operator+.  Everything compiles fine
| > when the
| > operator+ overload is not present.  The code compiles as is under
| > gcc-3.4.
| > What gives?
| 
| This is a bug in your code.  See PR 19404 and PR 20589.

Or this is a bug in the standard.  There is an active core issue for
it.  And I sent a request for further clarification and rationale.
(I've heard some rumours about manglings, but they don't make sense to me).

-- Gaby


RE: Problem with use of anonymous types

2005-05-06 Thread Julian Cummings
Hmmm... I just read through the bug reports you cited.  Sounds to me like
this is still somewhat of an open issue, as to whether the compiler should
issue an error in these cases or simply silently discard any templated
function as a possible match for an operation involving an unnamed type.  As
was pointed out in the discussion, this is a *disastrous* change in the
standard behavior of gcc because it essentially makes it impossible to
safely use an unnamed enum type in an arithmetic operation.  There is bound
to be some template function overload declared in some header file somewhere
that suddenly makes your code not work.  I am shocked that there is no
compiler flag made available to restore the previous behavior, especially in
light of the fact that the disposition of this issue remains unresolved.  I
have checked several other C++ compilers now (Intel icc 8.1 and IBM xlC 7.0,
for instance) and they all accept my example.

I also wish to point out that my example differs somewhat from the ones that
were given in the previous bug reports you cited, in that mine involves
arithmetic operations.  My understanding is that enumerators (even from an
unnamed enumeration) are to be treated as integers by default for arithmetic
operations.  This differs from the treatment for operators such as == and
<<.  (This is from the end of Section 4.8 of Stroustrup's book.  Perhaps
Stroustrup and the ANSI C++ standard differ here.)

Regards, Julian C.


> -Original Message-
> From: Andrew Pinski [mailto:[EMAIL PROTECTED] 
> Sent: Friday, May 06, 2005 5:09 PM
> To: Julian Cummings
> Cc: gcc-bugs@gcc.gnu.org
> Subject: Re: Problem with use of anonymous types
> 
> 
> On May 6, 2005, at 8:09 PM, Julian Cummings wrote:
> 
> > People are reporting trouble compiling blitz with 
> gcc-4.0.0, and the 
> > compiler errors are resulting from the use of unnamed 
> enums.  A simple 
> > code illustrates the problem:
> >
> >   struct nullType {};
> >   template  inline T operator+(const T& a, nullType) { 
> > return a; }
> >   enum named { namedA = 1, namedB = 2 };
> >   enum { unnamedA = 2, unnamedB = 4 };
> >   struct bar {
> > enum { namedC = namedA + namedB,
> >unnamedC = unnamedA + unnamedB };
> >   };
> >   int main() {
> >   }
> >
> > The gcc compiler complains about trying to add unnamedA and 
> unnamedB.
> > Apparently it gets confused by the presence of the 
> operator+ overload 
> > for the empty struct nullType.  I don't see why the compiler would 
> > think that the anonymous enumerators unnamedA or unnamedB 
> would match 
> > with type nullType.  Enumerators are supposed to default to 
> integers 
> > when used in arithmetic operations such as operator+.  Everything 
> > compiles fine when the
> > operator+ overload is not present.  The code compiles as is under
> > gcc-3.4.
> > What gives?
> 
> This is a bug in your code.  See PR 19404 and PR 20589.
> 
> -- Pinski
> 
> 




Re: Problem with use of anonymous types

2005-05-06 Thread Andrew Pinski
On May 6, 2005, at 8:09 PM, Julian Cummings wrote:
People are reporting trouble compiling blitz with gcc-4.0.0, and the
compiler errors are resulting from the use of unnamed enums.  A simple 
code
illustrates the problem:

  struct nullType {};
  template  inline T operator+(const T& a, nullType) { 
return a;
}
  enum named { namedA = 1, namedB = 2 };
  enum { unnamedA = 2, unnamedB = 4 };
  struct bar {
enum { namedC = namedA + namedB,
   unnamedC = unnamedA + unnamedB };
  };
  int main() {
  }

The gcc compiler complains about trying to add unnamedA and unnamedB.
Apparently it gets confused by the presence of the operator+ overload 
for
the empty struct nullType.  I don't see why the compiler would think 
that
the anonymous enumerators unnamedA or unnamedB would match with type
nullType.  Enumerators are supposed to default to integers when used in
arithmetic operations such as operator+.  Everything compiles fine 
when the
operator+ overload is not present.  The code compiles as is under 
gcc-3.4.
What gives?
This is a bug in your code.  See PR 19404 and PR 20589.
-- Pinski


Problem with use of anonymous types

2005-05-06 Thread Julian Cummings
People are reporting trouble compiling blitz with gcc-4.0.0, and the
compiler errors are resulting from the use of unnamed enums.  A simple code
illustrates the problem:

  struct nullType {};
  template  inline T operator+(const T& a, nullType) { return a;
}
  enum named { namedA = 1, namedB = 2 };
  enum { unnamedA = 2, unnamedB = 4 };
  struct bar {
enum { namedC = namedA + namedB,
   unnamedC = unnamedA + unnamedB };
  };
  int main() {
  }

The gcc compiler complains about trying to add unnamedA and unnamedB.
Apparently it gets confused by the presence of the operator+ overload for
the empty struct nullType.  I don't see why the compiler would think that
the anonymous enumerators unnamedA or unnamedB would match with type
nullType.  Enumerators are supposed to default to integers when used in
arithmetic operations such as operator+.  Everything compiles fine when the
operator+ overload is not present.  The code compiles as is under gcc-3.4.
What gives?

Thanks, Julian C.

Dr. Julian C. CummingsOffice: PB-111
Caltech/CACR, MC 158-79   Phone:  626-395-2543
1200 E. California Blvd.  Fax:626-584-5917
Pasadena, CA 91125