www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/26/20:00:46

From: horst DOT kraemer AT snafu DOT de (Horst Kraemer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How can I tell if it's a bug from DJGPP or GCC?
Date: Tue, 22 Sep 1998 11:46:14 GMT
Organization: [Posted via] Interactive Networx
Message-ID: <36078819.377336654@news.snafu.de>
References: <6u7smk$9t7$1 AT nnrp1 DOT dejanews DOT com>
NNTP-Posting-Host: n242-78.berlin.snafu.de
Lines: 91
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Tue, 22 Sep 1998 10:04:05 GMT, D DOT J DOT Eleveld AT anest DOT azg DOT nl wrote:

>---bug1.cc---
>/* BUG: The calling of destructors for (class) statically declared classes
>   is done in global scope and not class scope like it should. */

>class singelton
>{
> private:
>   singelton() { };
>   ~singelton() { };

> public:
>   static singelton instance;
>};

>singelton singelton::instance;

>/*
>I get these errors:

>bug1.cc:12: warning: all member functions in class `singelton' are private
>bug1.cc:12: warning: `class singelton' only defines a private destructor and
>has no friends bug1.cc: In function `(static destructors for bug1.cc)':
>bug1.cc:8: `singelton::~singelton()' is private bug1.cc:33: within this
>context

>Small problem:
>The warning about all member functions being private and the class having no
>friends is not useful when there are static instances of the class.

Why ?

>Bug:
>The static singleton is within the scope of class and should be able to be
>destructed, but DJGPP is trying to destroy it at global scope.
>*/

The scope of the declaration has nothing to do with scope of
"destruction". The scope of "contruction" of singelton::instance is
the scope of the class by definition. The scope of destruction is the
scope of the definition - i.e. global scope. The d'tor is not
accessible at global scope.

>---bug2.cc---
>/* BUG: Constant enum's arent always handled correctly */


The same would happen with straightforward 'int' instead of 'enum
index'

>[...]
>/* This assignment seems to be being skipped */
>const index problem = GetVariable();

>void Test(index event)
>{
>  switch(event)
>  {
>    /* Error occurs here */
>    case problem:
>      break;
>    default:
>  }

>}

>/*
>I get these errors:

>bug2.cc: In function `void Test(enum index)':
>bug2.cc:25: case label `problem' does not reduce to an integer constant
>bug2.cc:27: warning: unreachable code at beginning of switch statement
>bug2.cc:28: parse error before `}'

>I'm declaring a enum that's const so that should be a number, and not
>just treated like a define, as it appears to be doing here, otherwise
>side effects aren't handled properly.

A case label has to be a "constant integral expression". By definition
a constant integral expression is a "literal" expression or a const
variable initializid by a "literal expression".

The spirit of this requirement is that case labels have to be known at
compile time in order to produce efficient code. This is not the case
if you assign a value to a const variable through a function call.


Regards
Horst

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019