From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10338 invoked by alias); 14 Jul 2002 15:56:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 10298 invoked by uid 71); 14 Jul 2002 15:56:01 -0000 Resent-Date: 14 Jul 2002 15:56:01 -0000 Resent-Message-ID: <20020714155601.10296.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, a9804814@unet.univie.ac.at Received: (qmail 6705 invoked by uid 61); 14 Jul 2002 15:52:39 -0000 Message-Id: <20020714155239.6704.qmail@sources.redhat.com> Date: Sun, 14 Jul 2002 08:56:00 -0000 From: a9804814@unet.univie.ac.at Reply-To: a9804814@unet.univie.ac.at To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/7308: template-class member functions / namespace scope resolution in conjunction with template specialization X-SW-Source: 2002-07/txt/msg00446.txt.bz2 List-Id: >Number: 7308 >Category: c++ >Synopsis: template-class member functions / namespace scope resolution in conjunction with template specialization >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: accepts-illegal >Submitter-Id: net >Arrival-Date: Sun Jul 14 08:56:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: a9804814@unet.univie.ac.at >Release: gnu 2.95.3-6 (mingw special) >Organization: >Environment: >Description: ERROR 1: The following short program consists of a template definition in a header-file, and a program file (driver program) which instantiates the template class. The definitions in template-classes can be grouped into type-dependent definitions (operation using the templated type) and type-independent types (operations which do not require the type of the template parameters, like the member function "Print_Name" below (I know, this should be a static member function, but lets concentrate on the bug). The declaration of operands in type-independent operations must be known at the time these members are DEFINED (and not when the class'es / member function's point-of-instantiation is reached). In fact, the function "Print_Name" uses std::cout and std::endl as (type-independent) operands. However, none of these is #included before the definition of the template class. The definition of this function should be in error, because is not #included before the definition of the function ends. Here the program: // in header-File "name_resolution.hpp" #ifndef TEST_CLASS_HPP #define TEST_CLASS_HPP template class Test_Class { public: // should be in error, as type-independent operands // std::cout and std::endl aren't yet declared void Print_Name() const {std::cout << "test_class" << std::endl;} private: T Object__; }; #endif // in program file #include "name_resolution.hpp" #include int main(int argc, char* argv[]) { Test_Class TClass; TClass.Print_Name(); return 0; } ERROR 2: When template classes are defined in namespaces, then all specialization have to be declared WITHIN THE SAME NAMESPACE (the definitions of the specialization can be defined in other namespaces). In the program below, namespace "Inner_Name_Space", which is itself a member of namespace "Outer_Name_Space", defines template class, and does not declare nor define any specializations. However, in "Outer_Name_Space" a specialized function is defined. In main(), this specialized function is then used. This should not be the case, as only specializations declared within exactly the same namespace scope as the template-class definition itself are accepted / considered during name resolution. #include namespace Outer_Name_Space { namespace Inner_Name_Space { template class Test_Class { public: Test_Class(const T & Init) : Value_(Init) {} const T & Value() const {return Value_;} void Value(const T & New_Value) {Value_ = New_Value;} private: T Value_; }; } template <> void Inner_Name_Space::Test_Class:: Value(const int & New_Value) { std::cout << "setting new 'int' - Value." << std::endl; Value_ = New_Value; } } //-------------------- int main(int argc, char* argv[]) { using Outer_Name_Space::Inner_Name_Space::Test_Class; Test_Class A(745); // calls specialized member function, but shouldn't A.Value(-34343); cout << A.Value(); return 0; } best regards, Thomas Mang >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: