Base class type name injected into derived class

  • Follow


I've run across a strange problem that only seems to happen with EDG
compilers (Intel and Comeau.)  Since virtually every time I find an
EDG "bug" it's usually that my understanding of C++ was wrong, not the
compiler, I'm wondering if there is something to learn in this case
too, or if I really have found a bug.

  class Base_Class
  {
  protected:
    enum Value { foo };
  };

  class Derived : private Base_Class
  {
  public:
    Value v;
    using Base_Class::Value; // ERROR
  };

The error is this:
error: "Value" has already been declared in the current scope
    using Base_Class::Value;
                      ^

If I switch the order of the lines in Derived, such that "using" comes
before the declaration of v, then all is well.

Should the USE of a type in the base class implicitly declare that
type name in the derived class?  I tried reading the standard, and
section 3.3.1 seemed the most close to relevant, but I didn't see
anything to support this behavior.

Thanks.

Chris

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply cuzdav 7/20/2004 9:42:30 PM

On 20 Jul 2004 17:42:30 -0400, Chris Uzdavinis wrote:

>I've run across a strange problem that only seems to happen with EDG
>compilers (Intel and Comeau.)  Since virtually every time I find an
>EDG "bug" it's usually that my understanding of C++ was wrong, not the
>compiler, I'm wondering if there is something to learn in this case
>too, or if I really have found a bug.
>
>  class Base_Class
>  {
>  protected:
>    enum Value { foo };
>  };
>
>  class Derived : private Base_Class
>  {
>  public:
>    Value v;
>    using Base_Class::Value; // ERROR
>  };
>
>The error is this:
>error: "Value" has already been declared in the current scope
>    using Base_Class::Value;
>                      ^
>
>If I switch the order of the lines in Derived, such that "using" comes
>before the declaration of v, then all is well.
>
>Should the USE of a type in the base class implicitly declare that
>type name in the derived class?  I tried reading the standard, and
>section 3.3.1 seemed the most close to relevant, but I didn't see
>anything to support this behavior.


Hi Chris

3.3.6 para 2 seems to support EDG here, though the error message doesn't
seem meaningful.
<3.3.3/2>
A name N used in a class S shall refer to the same declaration in its
context and when re-evaluated in the completed scope of S. No diagnostic
is required for a violation of this rule.


So the first reference to Value in the derived class refers to the base
class declaration, but in the completed scope of S, the lookup of Value
finds the (using) declaration in the derived class.  I don't know if
this is what's causing EDG to complain - it seems a lot of effort for a
compiler to detect this error.

I agree EDG isn't wrong very often.  I discovered the following apparent
EDG non-compliance recently.  This codes jumps past the declaration of a
non-POD object into it's scope.  6.7 para 3 defines this to be
ill-formed code but Comeau reports no error.


struct s1 {
    int k;
};

struct s2 : public s1 {
};

int k;

int main()
{
    start:
    goto next;
    s2 x2;
    next:
    k = x2.k;
    goto start;
}

Graeme

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Graeme 7/21/2004 8:03:32 PM


1 Replies
206 Views

(page loaded in 0.036 seconds)

Similiar Articles:













7/23/2012 4:36:17 AM


Reply: