pedantic: not fussing enough?

Carlos Pita cpitaar@yahoo.com.ar
Thu Jul 12 00:40:00 GMT 2001


...following with the pedantic thread...



3)  <<<<<<<<<<<<<<<<<<<<<<

3.3.2.2

Local scope
....
 The potential scope of a ***function parameter name in a function
definition*** (8.4) begins at its point of declaration. If the function has
a function try-block the potential scope of a parameter ends at the end of
the last associated handler, else it ends at the end of the outermost block
of the function definition. A parameter name shall not be redeclared in the
outermost block of the function definition nor in the outermost block of any
handler associated with a function try-block .
....

3.3.3.1

Function prototype scope

 In a function declaration, or in any function declarator ***except the
declarator of a function definition*** (8.4), names of parameters (if
supplied) have function prototype scope, which terminates at the end of the
nearest enclosing function declarator.

3.3.5

... for an elaborated-type-specifier of the form class-key identifier
 *a* if the elaborated-type-specifier is used in the decl-specifier-seq or
parameter-declaration-clause of a function defined in namespace scope, the
identifier is declared as a class-name in the namespace that contains the
declaration;
 *b* otherwise, except as a friend declaration, the identifier is declared
in the smallest non-class, non-function-prototype scope that contains the
declaration...

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

class X {
public:
  void fa(class A* a) {  // declaration of a is in local scope
    class B fb(); // declaration of fb is in local scope
    B *pb; // Ok
  }
  A *pa; // Wrong, previous declaration of A should be confined to fa  (rule
*b*)   (1)
  B *pb; // Wrong, idem (rule *b*)    (2)
  void fc(class C* c); // declaration of c is in function prototype scope
  C *pc; // Right
};

namespace Y {
  void fa(class A* a) {  // declaration of a is in local scope
    //...
  }
  A *pa; // Right. This time fa is defined in a namespace scope and previous
             // declaration of A is used in its parameter-declaration-clause
(rule *a*)
};

int main() {
//....
}

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

 (2), of course, reports an error. But (1) compiles without problems. I
think this is a violation to the standard. In fact, note that if it wasn't
one, rule *a* would be only a special case of rule *b*: the
elaborated-type-specifier is considered to be used in function prototype
scope (this is the wrong hypothesis) and because the function definition is
in namespace scope (according to rule *a*) the "smallest non-class,
non-function-prototype scope that contains the declaration" will be the
namespace that contains the declaration, which reduces rule *a* to a case of
rule *b*. But if the elaborated-type-specifier is considered to be used in a
local scope, the rule *a* is in fact necessary. I'm not pretending that this
is the decisive argument: that's the reason I'm quoting you the definitions
of function prototype scope and local scope. Although perhaps they are not
the clearest definitions I've seen, I would say that they make clear the
fact that declaration of A is in local scope (in both cases) and declaration
of C is in function prototype scope in the program above.

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


 Is this kind of maddening grammar/semantics really really necessary?
Special rules everywhere! I'm a programmer and altough I don't write
compilers I like to read the standards besides any tutorial or reference
documentation for the languages I use. But the kind of erudition that this
standard request from me makes me feel that it's just waste of time to take
it too seriously. Perhaps I should only blindly program (ok, I´m being
kitsch and melodramatic), waiting for my compiler to fuss about every
violation to standards, and for the mad rules to result in just what common
sense would expect...but this isn't realistic anyway. I'm a little
disappointed (and the subtle ambiguities of the standard increses this
feeling). Surely I'm wrong. Perhaps I've born with the -pedantic switch
turned on. :)

See you,
 Carlos P.


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




More information about the Gcc-bugs mailing list