public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "keean@fry-it.com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/53573] template type dependent name resolution broken
Date: Tue, 05 Jun 2012 11:26:00 -0000	[thread overview]
Message-ID: <bug-53573-4-UDS2s0U3uh@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-53573-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #13 from Keean Schupke <keean@fry-it.com> 2012-06-05 11:25:40 UTC ---
(In reply to comment #9)

>From ISO14882 14.6 - Name resolution [temp.res]

-8- When looking for the declaration of a name used in a template definition,
the usual lookup rules (basic.lookup.unqual, basic.lookup.koenig) are used for
nondependent names. The lookup of names dependent on the template parameters is
postponed until the actual template argument is known (temp.dep). [Example:

#include <iostream>
using namespace std;

template<class T> class Set {
    T* p;
    int cnt;
public:
    Set();
    Set<T>(const Set<T>&);
    void printall()
    {
        for (int i = 0; i<cnt; i++)
            cout << p[i] << '\n';
    }
    //  ...
};
in the example, i is the local variable i declared in printall, cnt is the
member cnt declared in Set, and cout is the standard output stream declared in
iostream. However, not every declaration can be found this way; the resolution
of some names must be postponed until the actual template-arguments are known.
For example, even though the name operator<< is known within the definition of
printall() and a declaration of it can be found in <iostream>, the actual
declaration of operator<< needed to print p[i] cannot be known until it is
known what type T is (temp.dep). ]
-9- If a name does not depend on a template-parameter (as defined in temp.dep),
a declaration (or set of declarations) for that name shall be in scope at the
point where the name appears in the template definition; the name is bound to
the declaration (or declarations) found at that point and this binding is not
affected by declarations that are visible at the point of instantiation.
[Example:

void f(char);

template<class T> void g(T t)
{
    f(1);                   //   f(char)
    f(T(1));                //  dependent
    f(t);                   //  dependent
    dd++;                   //  not dependent
                //  error: declaration for dd not found
}
void f(int);

double dd;
void h()
{
    g(2);                   //  will cause one call of  f(char)  followed
                //   by two calls of  f(int)
    g('a');                 //  will cause three calls of  f(char)
}



So it was like this in 1998, and it is the same in the latest working draft. 


--- end example]

> (In reply to comment #2)
> > The function called in the template definition is clearly dependent on the
> > template parameter 'T' and therefore itsname should be resolved at the point of
> > instantiation where 'g' is clearly defined and in scope (and is not local). The
> > error message says: "no declarations were found by argument-dependent lookup at
> > the point of instantiation" when 'g' should be found. 
> 
> Built-in types have no associated namespaces so ADL can not find 'g' via ADL. A
> declaration must be visible at the point of definition.
> 
> The example in comment 1 is ill-formed.
> 
> Paragraph 10 doesn't apply because the call is clearly dependent.
> 
> N.B. N3242 is not the C++ standard and neither is "C++ Special Edition" which
> is quite old now.


  parent reply	other threads:[~2012-06-05 11:26 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-04 13:08 [Bug c++/53573] New: template type dependant " keean@fry-it.com
2012-06-04 13:31 ` [Bug c++/53573] " keean@fry-it.com
2012-06-04 13:33 ` keean@fry-it.com
2012-06-04 13:44 ` [Bug c++/53573] template type dependent " keean@fry-it.com
2012-06-04 16:38 ` keean@fry-it.com
2012-06-04 17:13 ` keean@fry-it.com
2012-06-05  9:06 ` keean@fry-it.com
2012-06-05 10:02 ` manu at gcc dot gnu.org
2012-06-05 10:15 ` keean@fry-it.com
2012-06-05 10:54 ` redi at gcc dot gnu.org
2012-06-05 11:03 ` redi at gcc dot gnu.org
2012-06-05 11:07 ` keean@fry-it.com
2012-06-05 11:14 ` keean@fry-it.com
2012-06-05 11:26 ` keean@fry-it.com [this message]
2012-06-05 11:31 ` redi at gcc dot gnu.org
2012-06-05 11:34 ` redi at gcc dot gnu.org
2012-06-05 11:53 ` keean@fry-it.com
2012-06-05 11:54 ` redi at gcc dot gnu.org
2012-06-05 11:57 ` redi at gcc dot gnu.org
2012-06-05 12:55 ` keean@fry-it.com
2012-06-05 16:31 ` paolo.carlini at oracle dot com
2012-06-05 17:01 ` keean@fry-it.com
2012-06-05 17:30 ` redi at gcc dot gnu.org
2012-06-27  6:48 ` keean@fry-it.com

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=bug-53573-4-UDS2s0U3uh@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: link
Be 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).