public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Why is this code accepted?
@ 2001-04-16 14:58 Mike Stump
  2001-04-16 20:16 ` Alexandre Oliva
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Stump @ 2001-04-16 14:58 UTC (permalink / raw)
  To: gcc, nbecker

> To: gcc@gcc.gnu.org
> From: nbecker@fred.net
> Date: 16 Apr 2001 16:27:42 -0400

> This code compiles without complaint both on gcc-2.96 and on a
> recent gcc-3 snapshot, but doesn't link.  I suspect the
> initialization of the static "a" is invalid (I don't have a good
> reference handy), but isn't gcc behaviour wrong?

There was a g++ feature that allowed this to work, a while ago.
Someone broke that feature, and didn't remove the feature from all
places in the compiler that supported the feature.  As I recall, the
standard doesn't support this feature.

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Why is this code accepted?
@ 2001-04-17 19:41 Mike Stump
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Stump @ 2001-04-17 19:41 UTC (permalink / raw)
  To: aoliva, nbecker; +Cc: gcc

> Cc: Mike Stump <mrs@windriver.com>, gcc@gcc.gnu.org
> From: Alexandre Oliva <aoliva@redhat.com>
> Date: 17 Apr 2001 18:51:45 -0300

> On Apr 17, 2001, nbecker@fred.net wrote:

> > If it doesn't work shouldn't gcc reject it?

Oh, wait, I know what's wrong...

g++  -pedantic-errors -ansi -S t.cc
t.cc:13: ISO C++ forbids initialization of member constant `a' of non-integral 
   type `const double[]'

It works as designed, and if we add:

const double X::a[2];

to the program to meet the logical requirements of the extension, and
don't ask for the error, then it works as expected.  I was thinking
of a language without the clause:

4 If a  static data member is of  const integral or   const  enumeration
  type,  its  declaration  in  the  class  definition  can  specify  a
  constant-initializer which shall be an  integral  constant  expression
  (5.19).   In  that  case,  the  member can appear in integral constant
  expressions within its scope.  The member shall still be defined in  a  |
  namespace  scope  if it is used in the program and the namespace scope  |
  definition shall not contain an  initializer.

in it, sorry for the confusion.  This wording first appeared in the 95
(95-0029) version of the working paper, so it is new...  :-)

So, no, no extension was broken, and no, no bug is present.

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Why is this code accepted?
@ 2001-04-17 17:20 Mike Stump
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Stump @ 2001-04-17 17:20 UTC (permalink / raw)
  To: aoliva, nbecker; +Cc: gcc

> To: Alexandre Oliva <aoliva@redhat.com>
> Cc: Mike Stump <mrs@windriver.com>, gcc@gcc.gnu.org
> From: nbecker@fred.net
> Date: 17 Apr 2001 07:56:56 -0400

> If it doesn't work shouldn't gcc reject it?

Yes, like I said, I believe that the standard mandates that a
diagnostic is produced for that code.

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Why is this code accepted?
@ 2001-04-16 13:27 nbecker
  0 siblings, 0 replies; 7+ messages in thread
From: nbecker @ 2001-04-16 13:27 UTC (permalink / raw)
  To: gcc

This code compiles without complaint both on gcc-2.96 and on a recent gcc-3 snapshot,
but doesn't link.  I suspect the initialization of the static "a" is
invalid (I don't have a good reference handy), but isn't gcc behaviour
wrong?  If the initialization is invalid, why doesn't the compiler
complain (it doesn't even with -Wall)?  If not, why doesn't it link?
--------------------

cd /home/nbecker/bitexact/bitexact/
/opt/gcc/bin/g++ -o bug bug.cc
/tmp/ccZtF0aa.o: In function `X::X()   ':
/tmp/ccZtF0aa.o(.gnu.linkonce.t._ZN1XC1Ev+0xa): undefined reference to `X::a    '
/tmp/ccZtF0aa.o(.gnu.linkonce.t._ZN1XC1Ev+0xf): undefined reference to `X::a    '
collect2: ld returned 1 exit status

--------------------
#include <vector>
using namespace std;

class Y {
  vector<double> c;
public:
  Y (const double* a, const double* b) :
    c (a, b)
  {}
};

class X {
  static const double a[] = {1, 2};
  Y y;
public:
  X () :
    y (&a[0], &a[2])
  {}

};

main () {
  vector<X> x (2);
}
-------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-04-17 19:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-16 14:58 Why is this code accepted? Mike Stump
2001-04-16 20:16 ` Alexandre Oliva
2001-04-17  4:57   ` nbecker
2001-04-17 14:52     ` Alexandre Oliva
  -- strict thread matches above, loose matches on Subject: below --
2001-04-17 19:41 Mike Stump
2001-04-17 17:20 Mike Stump
2001-04-16 13:27 nbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).