From mboxrd@z Thu Jan 1 00:00:00 1970 From: stephen@bregmasoft.com To: gcc-gnats@gcc.gnu.org Subject: c++/2402: Problem with compile-time sizeof evaluation and templates Date: Tue, 27 Mar 2001 05:46:00 -0000 Message-id: <20010327134008.2008.qmail@sourceware.cygnus.com> X-SW-Source: 2001-03/msg00298.html List-Id: >Number: 2402 >Category: c++ >Synopsis: Problem with compile-time sizeof evaluation and templates >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: rejects-legal >Submitter-Id: net >Arrival-Date: Tue Mar 27 05:46:03 PST 2001 >Closed-Date: >Last-Modified: >Originator: stephen@bregmasoft.com >Release: GNU C++ version 3.1 20010326 (experimental) (i686-pc-linux-gnu) >Organization: >Environment: >Description: The following well-formed C++ program // -- begin tu.cpp -- template< class T > struct C { static T returnaT(); enum { itsSize = sizeof C::returnaT() }; }; int main(int argc, char* argv[]) { long aSize = C::itsSize; return 0; } // -- end tu.cpp - gives the following error on compile (g++ tu.cpp): tu.cpp: In instantiation of `C': tu.cpp:13: instantiated from here tu.cpp:13: no method `C::returnaT' Note that (a) there is too a C::returnaT, since it's defined in the previous line, and (2) it's not Smalltalk, there are no "methods," only member functions, so the error message text could be improved to say what it means. The problem only occurs with templated classes. The same code using a non-templated class compiles OK. There's a large body of standard-compliant code out there that relies on this sort of construct working. This code has never worked with any version of GCC, so it's not a regression. >How-To-Repeat: See description above. >Fix: >Release-Note: >Audit-Trail: >Unformatted: