public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10086: static const int unresolved in ? : construct
@ 2003-03-16  9:36 Gabriel Dos Reis
  0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Dos Reis @ 2003-03-16  9:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/10086; it has been noted by GNATS.

From: Gabriel Dos Reis <gdr@integrable-solutions.net>
To: "Giovanni Bajo" <giovannibajo@libero.it>
Cc: <gcc-gnats@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>, <chrisk@mysticlabs.com>
Subject: Re: c++/10086: static const int unresolved in ? : construct
Date: 16 Mar 2003 10:28:29 +0100

 "Giovanni Bajo" <giovannibajo@libero.it> writes:
 
 | http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 | r=10086
 
 I think arguments can be made for both sides (bug or not a bug) in
 this particular case.  Certainly understand what is going on involves
 understanding how the compiler is treating internal the expression 
 
     v ? A : B
 
 Certainly, it is not an integrable constant expression and it is an
 lvalue.  Wihch means the compiler is internally taking the address of
 both Base::A and Base::B.  Hence the link error.
 
 | I'm not sure what it is going on. I know that the standard says that you
 | still have to define an initialized static const member (even if there is an
 | open defect report about this, I believe). But then, why this should work:
 | 
 | struct Foo
 | {
 |    static const int A = 0;
 | };
 | 
 | int main(void)
 | {
 |    return Foo::A;
 | }
 | 
 | This one compiles and links correctly on G++ 3.2, but it should not. 
 
 In the above, Foo::A is used in a such way that its definition isn't
 needed, i.e. its address isn't taken.
 
 I agree with you that all that is confusing.  A reason why I've always
 thought of that as a misfeature -- it doesn't scale easily.
 
 -- Gaby


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

* Re: c++/10086: static const int unresolved in ? : construct
@ 2003-03-16  1:06 Giovanni Bajo
  0 siblings, 0 replies; 6+ messages in thread
From: Giovanni Bajo @ 2003-03-16  1:06 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/10086; it has been noted by GNATS.

From: "Giovanni Bajo" <giovannibajo@libero.it>
To: <gcc-gnats@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<chrisk@mysticlabs.com>,
	<nobody@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>
Cc:  
Subject: Re: c++/10086: static const int unresolved in ? : construct
Date: Sun, 16 Mar 2003 02:02:59 +0100

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 r=10086
 
 I'm not sure what it is going on. I know that the standard says that you
 still have to define an initialized static const member (even if there is an
 open defect report about this, I believe). But then, why this should work:
 
 struct Foo
 {
    static const int A = 0;
 };
 
 int main(void)
 {
    return Foo::A;
 }
 
 This one compiles and links correctly on G++ 3.2, but it should not. The
 poster reported a simple case when just defining a local variable to mirror
 the contents of the static const member changes the compilation failure into
 a success. IMO there is an issue here (probably related to the optimized
 which is stripping away the symbol in some situations, thus avoiding the
 linker error).
 
 Giovanni Bajo
 


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

* Re: c++/10086: static const int unresolved in ? : construct
@ 2003-03-15 17:06 Wolfgang Bangerth
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Bangerth @ 2003-03-15 17:06 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/10086; it has been noted by GNATS.

From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: Chris Kappler <chrisk@mysticlabs.com>
Cc: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>
Subject: Re: c++/10086: static const int unresolved in ? : construct
Date: Sat, 15 Mar 2003 11:03:22 -0600 (CST)

 > I do not agree. 
 
 That doesn't make it right. The standard says that you need to have 
 definitions of static variables like
   const int Base::A;
 and it allows the compiler to make use of these variables without using 
 the provided constant initializers. Just because it uses them in one 
 context and not in another doesn't mean you should rely on that.
 
 W.
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth             email:            bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth/
 
 


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

* Re: c++/10086: static const int unresolved in ? : construct
@ 2003-03-15 16:56 Chris Kappler
  0 siblings, 0 replies; 6+ messages in thread
From: Chris Kappler @ 2003-03-15 16:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/10086; it has been noted by GNATS.

From: "Chris Kappler" <chrisk@mysticlabs.com>
To: <bangerth@dealii.org>,
	<chrisk@mysticlabs.com>,
	<gcc-bugs@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>,
	<nobody@gcc.gnu.org>,
	<gcc-gnats@gcc.gnu.org>
Cc:  
Subject: Re: c++/10086: static const int unresolved in ? : construct
Date: Sat, 15 Mar 2003 11:55:43 -0500

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0004_01C2EAE9.CED59AA0
 Content-Type: text/plain;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 
 I do not agree.  In the attachment to this email, the commented code
 compiles perfectly.  The uncommented code results in a linker error.  I
 believe that the two pieces of code are semantically equivalent.
 
 ----- Original Message -----
 From: <bangerth@dealii.org>
 To: <chrisk@mysticlabs.com>; <gcc-bugs@gcc.gnu.org>; <gcc-prs@gcc.gnu.org>;
 <nobody@gcc.gnu.org>
 Sent: Friday, March 14, 2003 5:33 PM
 Subject: Re: c++/10086: static const int unresolved in ? : construct
 
 
 > Synopsis: static const int unresolved in ? : construct
 >
 > State-Changed-From-To: open->closed
 > State-Changed-By: bangerth
 > State-Changed-When: Fri Mar 14 22:33:31 2003
 > State-Changed-Why:
 >     Not a bug. You need a definition of the variable.
 >
 >
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 r=10086
 
 ------=_NextPart_000_0004_01C2EAE9.CED59AA0
 Content-Type: application/octet-stream;
 	name="bug.cpp"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="bug.cpp"
 
 =0A=
 #include <iostream>=0A=
 using namespace std;=0A=
 =0A=
 class Base {=0A=
 public:=0A=
   const static int A =3D 0;=0A=
   const static int B =3D 1;=0A=
 };=0A=
 =0A=
 class Child : public Base {=0A=
 public:=0A=
   void printAB(bool v);=0A=
 };=0A=
 =0A=
 =0A=
 void Child::printAB(bool v) {=0A=
   int aa =3D A;=0A=
   int bb =3D B;=0A=
   int a =3D (v)?A:B;       // causes a linker error=0A=
   int b =3D (!v)?A:B;      // causes a linker error=0A=
   //int a =3D (v)?aa:bb;   // compiles and runs if uncommented=0A=
   //int b =3D (!v)?aa:bb;  // compiles and runs if uncommented=0A=
 =0A=
   cout<<"a is "<<a<<" b is "<<b<<endl;=0A=
 }=0A=
 =0A=
 int main() {=0A=
   Child c;=0A=
   c.printAB(true);=0A=
   c.printAB(false);=0A=
 }=0A=
 =0A=
 
 ------=_NextPart_000_0004_01C2EAE9.CED59AA0--
 


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

* Re: c++/10086: static const int unresolved in ? : construct
@ 2003-03-14 22:33 bangerth
  0 siblings, 0 replies; 6+ messages in thread
From: bangerth @ 2003-03-14 22:33 UTC (permalink / raw)
  To: chrisk, gcc-bugs, gcc-prs, nobody

Synopsis: static const int unresolved in ? : construct

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Fri Mar 14 22:33:31 2003
State-Changed-Why:
    Not a bug. You need a definition of the variable.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10086


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

* c++/10086: static const int unresolved in ? : construct
@ 2003-03-14 21:36 chrisk
  0 siblings, 0 replies; 6+ messages in thread
From: chrisk @ 2003-03-14 21:36 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10086
>Category:       c++
>Synopsis:       static const int unresolved in ? : construct
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 14 21:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Chris Kappler
>Release:        gcc version 3.2 20020927 (prerelease)
>Organization:
>Environment:
Cygwin
>Description:
const static int variables show up as unresolved in the linker.
>How-To-Repeat:
g++ bug.cpp
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="bug.cpp"
Content-Disposition: inline; filename="bug.cpp"


#include <iostream>
using namespace std;

class Base {
public:
  const static int A = 0;
  const static int B = 1;
};

class Child : public Base {
public:
  void printAB(bool v);
};


void Child::printAB(bool v) {
  int a = (v)?A:B;
  int b = (v)?A:B;

  cout<<"a is "<<a<<" b is "<<b<<endl;
}

int main() {
  Child c;
  c.printAB(true);
  c.printAB(false);
}


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

end of thread, other threads:[~2003-03-16  9:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-16  9:36 c++/10086: static const int unresolved in ? : construct Gabriel Dos Reis
  -- strict thread matches above, loose matches on Subject: below --
2003-03-16  1:06 Giovanni Bajo
2003-03-15 17:06 Wolfgang Bangerth
2003-03-15 16:56 Chris Kappler
2003-03-14 22:33 bangerth
2003-03-14 21:36 chrisk

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).