public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45501]  New: Compiler does not find template function if member is addressed with "this"
@ 2010-09-02 16:51 grottel at vis dot uni-stuttgart dot de
  2010-09-02 17:17 ` [Bug c++/45501] " paolo dot carlini at oracle dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: grottel at vis dot uni-stuttgart dot de @ 2010-09-02 16:51 UTC (permalink / raw)
  To: gcc-bugs

Command line:
g++ -o File.o File.cpp

Testes with gcc 4.5.0 and 4.3.1

Content of .cpp-file:
#include <cstdio>

template<class T>
class MetaObj {
public:
    const char *GetText(void) const {
        return T::GetTextStatic();
    }
};

class Obj {
public:
    static const char *GetTextStatic(void) {
        return "Text";
    }
};

class Printer {
public:
    void PrintText(const char *who, const char *what) {
        printf("%s: %s\n", who, what);
    }
    template<class T> void PrintTextFrom(void) {
        T *d = new T();
        PrintText("Printer-Meta", d->GetText());
        delete d;
    }
};

template<unsigned int CNT>
class MultiInfoPrinter {
public:
    MultiInfoPrinter(void) {
        for (unsigned int i = 0; i < CNT; i++) {
            this->prn.PrintText("MultiInfoPrinter-Static",
Obj::GetTextStatic());   // works
            this->prn.PrintText("MultiInfoPrinter-Meta",
MetaObj<Obj>().GetText()); // works
            prn.PrintTextFrom< MetaObj<Obj> >();                               
    // works
            this->prn.PrintTextFrom< MetaObj<Obj> >();                         
    // WORKS NOT with gcc, but with icc!!! WHY???
        }
    }
private:
    Printer prn;
};

int main(int argc, char *argv[]) {
    MultiInfoPrinter<2> p;
}


-- 
           Summary: Compiler does not find template function if member is
                    addressed with "this"
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: grottel at vis dot uni-stuttgart dot de


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


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

* [Bug c++/45501] Compiler does not find template function if member is addressed with "this"
  2010-09-02 16:51 [Bug c++/45501] New: Compiler does not find template function if member is addressed with "this" grottel at vis dot uni-stuttgart dot de
@ 2010-09-02 17:17 ` paolo dot carlini at oracle dot com
  2010-09-02 17:45 ` paolo dot carlini at oracle dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-09-02 17:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2010-09-02 17:16 -------
Since PrintTextFrom is a template, you can (should) write:

  this->prn.template PrintTextFrom< MetaObj<Obj> >();

which works with both compilers. Since apparently ICC 11.1 likes in strict mode
also the form without 'template' let's ask Jason if we are right in rejecting
it (while accepting it without this->)


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu dot org


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


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

* [Bug c++/45501] Compiler does not find template function if member is addressed with "this"
  2010-09-02 16:51 [Bug c++/45501] New: Compiler does not find template function if member is addressed with "this" grottel at vis dot uni-stuttgart dot de
  2010-09-02 17:17 ` [Bug c++/45501] " paolo dot carlini at oracle dot com
@ 2010-09-02 17:45 ` paolo dot carlini at oracle dot com
  2010-09-03  1:36 ` jason at gcc dot gnu dot org
  2010-09-03  9:10 ` paolo dot carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-09-02 17:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from paolo dot carlini at oracle dot com  2010-09-02 17:44 -------
As a matter of fact, basing on my rough understanding of '.template', GCC may
well be correct: my rule of thumb is that 'template' is required when the
construct before the period depends on a template parameter: by itself prn,
being a Printer, doesn't; this->prn does, because this points to a
MultiInfoPrinter.


-- 


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


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

* [Bug c++/45501] Compiler does not find template function if member is addressed with "this"
  2010-09-02 16:51 [Bug c++/45501] New: Compiler does not find template function if member is addressed with "this" grottel at vis dot uni-stuttgart dot de
  2010-09-02 17:17 ` [Bug c++/45501] " paolo dot carlini at oracle dot com
  2010-09-02 17:45 ` paolo dot carlini at oracle dot com
@ 2010-09-03  1:36 ` jason at gcc dot gnu dot org
  2010-09-03  9:10 ` paolo dot carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-09-03  1:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jason at gcc dot gnu dot org  2010-09-03 01:36 -------
prn and this->prn are equivalent.  Specifically, the type of *this is the
current scope, so although it is a dependent type it is not a dependent scope
and .template should not be needed.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-09-03 01:36:05
               date|                            |


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


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

* [Bug c++/45501] Compiler does not find template function if member is addressed with "this"
  2010-09-02 16:51 [Bug c++/45501] New: Compiler does not find template function if member is addressed with "this" grottel at vis dot uni-stuttgart dot de
                   ` (2 preceding siblings ...)
  2010-09-03  1:36 ` jason at gcc dot gnu dot org
@ 2010-09-03  9:10 ` paolo dot carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-09-03  9:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo dot carlini at oracle dot com  2010-09-03 09:09 -------
Ah, ok, thanks Jason.


-- 


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


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

end of thread, other threads:[~2010-09-03  9:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-02 16:51 [Bug c++/45501] New: Compiler does not find template function if member is addressed with "this" grottel at vis dot uni-stuttgart dot de
2010-09-02 17:17 ` [Bug c++/45501] " paolo dot carlini at oracle dot com
2010-09-02 17:45 ` paolo dot carlini at oracle dot com
2010-09-03  1:36 ` jason at gcc dot gnu dot org
2010-09-03  9:10 ` paolo dot carlini at oracle dot com

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