public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: a9804814@unet.univie.ac.at To: gcc-gnats@gcc.gnu.org Subject: c++/7308: template-class member functions / namespace scope resolution in conjunction with template specialization Date: Sun, 14 Jul 2002 08:56:00 -0000 [thread overview] Message-ID: <20020714155239.6704.qmail@sources.redhat.com> (raw) >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 <iostream> 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 <typename T> 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 <iostream> int main(int argc, char* argv[]) { Test_Class<int> 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 <iostream> namespace Outer_Name_Space { namespace Inner_Name_Space { template <typename T> 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<int>:: 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<int> 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:
reply other threads:[~2002-07-14 15:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20020714155239.6704.qmail@sources.redhat.com \ --to=a9804814@unet.univie.ac.at \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).