public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19112] New: assignment from function to template fails
@ 2004-12-21 16:40 d dot hentrich at gmx dot de
  2004-12-21 17:37 ` [Bug c++/19112] " bangerth at dealii dot org
  0 siblings, 1 reply; 2+ messages in thread
From: d dot hentrich at gmx dot de @ 2004-12-21 16:40 UTC (permalink / raw)
  To: gcc-bugs

I try to assign a template to another template. Direct assignment works, 
but when I try to assign the result of a function call, gcc fails. Under 
the given canditates the expected one is listed. 
 
 
following code fails using gcc: 
 
==================================================================== 
// template test for gcc 
// 
 
template<class TEST> 
class Pointer 
{ 
public: 
    Pointer(TEST initValue): m_data(initValue) {} 
    Pointer(Pointer<TEST> &other): m_data(other.m_data) {} 
    virtual ~Pointer() {} 
 
    //Pointer<TEST> &operator = (Pointer<TEST> &other) { m_data = 
other.m_data; return *this; } 
 
private: 
    TEST m_data; 
}; 
 
 
template<class TEST> 
class UsePointer 
{ 
public: 
    UsePointer(Pointer<TEST> &point) 
        : m_localCopy(point) 
    {} 
 
    UsePointer(Pointer<TEST> point) 
    : m_localCopy(point) 
    { 
    } 
private: 
    Pointer<TEST> m_localCopy; 
}; 
 
 
Pointer<int> getSomething() 
{ 
    Pointer<int> result(4); 
    return result; 
} 
 
 
int main(int argc, char* argv[]) 
{ 
    UsePointer<int> user(getSomething()); 
        return 0; 
} 
==================================================================== 
with following output 
==================================================================== 
dierk@hochofen:~/Entwicklung/eigenes$ gcc -v -save-temps -c templates.cpp -o 
templtest 
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.5/specs 
Configured with: ../src/configure -v 
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib 
--enable-nls --without-included-gettext --enable-__cxa_atexit 
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm 
--enable-java-awt=xlib --enable-objc-gc i486-linux 
Thread model: posix 
gcc version 3.3.5 (Debian 1:3.3.5-2) 
 /usr/lib/gcc-lib/i486-linux/3.3.5/cc1plus -E -D__GNUG__=3 -quiet -v 
-D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=5 -D_GNU_SOURCE 
templates.cpp templates.ii 
ignoring nonexistent directory "/usr/i486-linux/include" 
#include "..." search starts here: 
#include <...> search starts here: 
 /usr/include/c++/3.3 
 /usr/include/c++/3.3/i486-linux 
 /usr/include/c++/3.3/backward 
 /usr/local/include 
 /usr/lib/gcc-lib/i486-linux/3.3.5/include 
 /usr/include 
End of search list. 
 /usr/lib/gcc-lib/i486-linux/3.3.5/cc1plus -fpreprocessed templates.ii -quiet 
-dumpbase templates.cpp -auxbase-strip templtest -version -o templates.s 
GNU C++ version 3.3.5 (Debian 1:3.3.5-2) (i486-linux) 
        compiled by GNU C version 3.3.5 (Debian 1:3.3.5-2). 
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129567 
templates.cpp: In function `int main(int, char**)': 
templates.cpp:45: error: no matching function for call to `Pointer<int>:: 
   Pointer(Pointer<int>)' 
templates.cpp:9: error: candidates are: Pointer<TEST>::Pointer(Pointer<TEST>&) 
   [with TEST = int] 
templates.cpp:8: error:                 Pointer<TEST>::Pointer(TEST) [with 
TEST 
   = int] 
templates.cpp:45: error:   initializing argument 1 of ` 
   UsePointer<TEST>::UsePointer(Pointer<TEST>) [with TEST = int]' 
====================================================================

-- 
           Summary: assignment from function to template fails
           Product: gcc
           Version: 3.3.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: d dot hentrich at gmx dot de
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: linux
GCC target triplet: linux


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/19112] assignment from function to template fails
  2004-12-21 16:40 [Bug c++/19112] New: assignment from function to template fails d dot hentrich at gmx dot de
@ 2004-12-21 17:37 ` bangerth at dealii dot org
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth at dealii dot org @ 2004-12-21 17:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-12-21 17:36 -------
gcc is correct: the result of getSomething is a temporary. Temporaries can 
only be bound to const references, not to non-const ones. Thus, the 
constructor 
    UsePointer(Pointer<TEST> &point)  
        : m_localCopy(point)  
    {}  
is not a candidate. In order to use the constructor 
    UsePointer(Pointer<TEST> point)  
    : m_localCopy(point)  
    {  
    }  
you need to be able to copy objects of type Pointer<int>, but then you 
run into the same problem of not having an appropriate copy constructor 
of Pointer that takes a constant reference. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-12-21 17:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-21 16:40 [Bug c++/19112] New: assignment from function to template fails d dot hentrich at gmx dot de
2004-12-21 17:37 ` [Bug c++/19112] " bangerth at dealii dot org

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).