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

mdorey at bluearc dot com gcc-bugzilla@gcc.gnu.org
Tue Mar 30 17:57:00 GMT 2004


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



More information about the Gcc-bugs mailing list