This is the mail archive of the gcc@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]

pedantic: not fussing enough?


Hi!

 I'm studying the ISO C++ standard in some detail. While I´m reading it I
use to compile some tests using g++ (3.0) with the -pedantic command line
option and to compare the actual results (reports) against the ones required
by the statements in the standard. I think it would be helpful to post any
possible violations to the standard I could find (except, of course, for
rules for which no diagnostic is required, which would not be a violation).
If you don't find it useful please say it to me.

 Below is a list of possible violations I've found this time. You will see
an excerpt from the standard first and then, just below it, a list of
commented examples showing where the problem seems to be.

See you,
    Carlos P.

PD: if you think I should only write the section numbers instead of quoting
the entire (or part of the) statements I'll just do it. .

1) <<<<<<<<<<<<<<<<<

3.3.4

Given a set of declarations in a single declarative region, each of which
specifies the same unqualified name, they shall
      * all refer to the same entity, or all refer to functions and function
templates; or
      * exactly one declaration shall declare a class name or enumeration
name that is not a typedef name and the other declarations shall all refer
to the same object or enumerator, or all refer to functions and function
templates; in this case the class name or enumeration name is hidden
(3.3.7). [Note: a namespace name or a class template name must be unique in
its declarative region (7.3.2, clause 14). ]

9.1.3

      An elaborated-type-specifier (7.1.5.3) can also be used as a
type-specifier as part of a declaration. It differs from a class declaration
in that if a class of the elaborated name is in scope the elaborated name
will refer to it. [Example:

struct s { int a; };

void g(int s)
{
 struct s* p = new struct s;               // global s
 p->a = s;                                 // local s
}

(Observation: a class declaration is also an elaborated-type-specifier of
the form 'class-key  identifier;' as stated in section 7.1.5.3. But
statement 9.1.3 is almost explicitly considering them as different
constructs... As it is in a lot of other cases, the standard is too vague
here again >:( ).

------------------
/*
 * This works without any pedantic complaint. I think it shouldn't: in both
 * examples a redeclaration of class 'a' is being done and neither every
 * declaration of 'a' refers to a function nor to the same entity. In any
 * case I can't see the point of the rule...perhaps having a class name
 * redeclared after the object/enumerator declaration would give the wrong
 * impression of putting the name into scope (when in fact it would still be
 * hidden).
 * class a should be accessed as an elaborate-type-specifier that is not
 * the sole component of a declaration, as in the declaration of h in the
 * main function.
 */

class a {
  int a;
  int b;
};

int a;
extern int a;

class a;  // violation! perhaps 'a' seems to be in scope (?)

int main() {
    .....
    class a h;
    .....
}

------------------

// Similar example:

class a {
  int a;
  int b;
};

int a(int);
int a(int, int);

class a;  // violation! perhaps 'a' seems to be in scope (?)

int main() {
    .....
}


>>>>>>>>>>>>>>>>>>




2)  <<<<<<<<<<<<<<<<<<

Again...


3.3.4

Given a set of declarations in a single declarative region, each of which
specifies the same unqualified name, they shall
      * all refer to the same entity, or all refer to functions and function
templates; or
      * exactly one declaration shall declare a class name or enumeration
name that is not a typedef name and the other declarations shall all refer
to the same object or enumerator, or all refer to functions and function
templates; in this case the class name or enumeration name is hidden
(3.3.7). [Note: a namespace name or a class template name must be unique in
its declarative region (7.3.2, clause 14). ]


And just remember that...

3.3

An entity is a value, object, subobject, base class subobject, array
element, variable, function, instance of a function, enumerator, **type**,
class member, template, or **namespace**.

9.1

A **class** is a **type**. Its name becomes a class-name (9.1) within its
scope.


---------------------

// The same name, two different entities which are not functions and
// which don't make a set of 2 elements:
// { class/enumeration, object/enumerator/function}

namespace X {
....
};

class X {
....
};

int main() {
....
}

>>>>>>>>>>>>>>>>>>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



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