This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c++/14785] New: member template function's parameter doesn't hide enclosing type completely


struct A {
  typedef int B;
    
  template <class B>
  void f (const B&) {
    int a [sizeof (B) == 1 ? 1 : -1];
  }
};

Produces:

egg.cpp: In member function `void A::f(const B&)':
egg.cpp:6: error: size of array `a' is negative

With 3.4.0 20040320.

If you agree it's a bug, then it's a regression over 3.3/3.1/2.95.  Is it a bug?
 Well, section 14.6.1.3 says "A template-parameter hides any entity with the
same name in the enclosing scope".  Is B a dependent name here?  I think so as
14.6.2.3.2 explicitly says that sizeof(type-id) is value-dependent though it
isn't type-dependent.  (The "definition" of value-dependent in 14.6.2.1 as "(on
the value of a non-type template parameter)" seems incomplete.)

Empirically, moving the typedef outside the struct causes the code to compile. 
Other examples which don't compile and which don't involve sizeof are easy to
construct, if sizeof turns out to be a bone of contention, but I thought the
sizeof-and-negative-array-size demonstrated the problem the most simply.

-- 
           Summary: member template function's parameter doesn't hide
                    enclosing type completely
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mdorey at bluearc dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14785


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