public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54755] New: Template instantiation confused by actual template argument definitions before and after template definition
@ 2012-09-29 18:13 e678961 at yahoo dot co.uk
  2012-09-29 19:06 ` [Bug c++/54755] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: e678961 at yahoo dot co.uk @ 2012-09-29 18:13 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54755
           Summary: Template instantiation confused by actual template
                    argument definitions before and after template
                    definition
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: e678961@yahoo.co.uk


The following code:-

// ---------------------------------------------

#include <iostream>

// Before
void Function ( int  )  { std::cout << "int\n";   }
void Function ( long  ) { std::cout << "long\n";  }

template <class x>
struct TemplateClass
{
  x  Variable;
  void MemberFunction() { Function(Variable); }
};

// After
void Function ( float ) { std::cout << "float\n"; }

int main ( int, char** ) {
  TemplateClass<int>    I;
  I.MemberFunction();

  TemplateClass<long>   L;
  L.MemberFunction();

  TemplateClass<float>  F;
  F.MemberFunction();
}

// ---------------------------------------------

gives the compiler error:- error: call of overloaded 'Function(float&)' is
ambiguous

However, if all definitions of Function are in the "Before" block, and none in
"After" it works.

If all definitions are in the "After" block, and none in the "Before" code, it
also works.

If the int version of Function is in the "Before" code and the others in
"After" all instantiations of the template use the int version because of
implicit type conversion.

This looks like a bug in the symbol lookup. All overloaded versions of Function
can be found if they are either before or after the definition of the template
that happens to use them, but only if they are all defined together. Separate
the definitions before and after the template definition and it goes wrong.

Note: iostream output has only been used in the example to illustrate the bug
using std output. The code can be further simplified by removing iostream and
the same thing happens.


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

* [Bug c++/54755] Template instantiation confused by actual template argument definitions before and after template definition
  2012-09-29 18:13 [Bug c++/54755] New: Template instantiation confused by actual template argument definitions before and after template definition e678961 at yahoo dot co.uk
@ 2012-09-29 19:06 ` redi at gcc dot gnu.org
  2012-09-29 23:08 ` daniel.kruegler at googlemail dot com
  2012-09-29 23:23 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2012-09-29 19:06 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-09-29 19:06:09 UTC ---
I haven't bothered analysing the code, but Comeau and Clang agree it's
ambiguous, so GCC is probably right.


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

* [Bug c++/54755] Template instantiation confused by actual template argument definitions before and after template definition
  2012-09-29 18:13 [Bug c++/54755] New: Template instantiation confused by actual template argument definitions before and after template definition e678961 at yahoo dot co.uk
  2012-09-29 19:06 ` [Bug c++/54755] " redi at gcc dot gnu.org
@ 2012-09-29 23:08 ` daniel.kruegler at googlemail dot com
  2012-09-29 23:23 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-09-29 23:08 UTC (permalink / raw)
  To: gcc-bugs


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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-09-29 23:07:59 UTC ---
(In reply to comment #1)
> I haven't bothered analysing the code, but Comeau and Clang agree it's
> ambiguous, so GCC is probably right.

I agree with Jonathan, the code is supposed to be ill-formed. This is so,
because the second stage of ADL is not allowed to consider overloads visible
*after* the point of the template definition where the call happens of function
argument types without associated namespaces.


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

* [Bug c++/54755] Template instantiation confused by actual template argument definitions before and after template definition
  2012-09-29 18:13 [Bug c++/54755] New: Template instantiation confused by actual template argument definitions before and after template definition e678961 at yahoo dot co.uk
  2012-09-29 19:06 ` [Bug c++/54755] " redi at gcc dot gnu.org
  2012-09-29 23:08 ` daniel.kruegler at googlemail dot com
@ 2012-09-29 23:23 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-09-29 23:23 UTC (permalink / raw)
  To: gcc-bugs


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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-09-29 23:23:06 UTC ---
Closing.


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

end of thread, other threads:[~2012-09-29 23:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-29 18:13 [Bug c++/54755] New: Template instantiation confused by actual template argument definitions before and after template definition e678961 at yahoo dot co.uk
2012-09-29 19:06 ` [Bug c++/54755] " redi at gcc dot gnu.org
2012-09-29 23:08 ` daniel.kruegler at googlemail dot com
2012-09-29 23:23 ` paolo.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).