public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55576] New: Fails to compile a call to template member function
@ 2012-12-03 15:27 antoshkka at gmail dot com
  2012-12-03 16:01 ` [Bug c++/55576] " redi at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: antoshkka at gmail dot com @ 2012-12-03 15:27 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55576
           Summary: Fails to compile a call to template member function
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: antoshkka@gmail.com


Created attachment 28860
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28860
Output of `gcc -v -save-temps -Wall -Wextra main.cpp`

When compiling following code:

struct factory {
 template <typename T>
 void * apply(void * address)
 {
  return new (address) T;
 }
};

template <typename T>
struct apply {
 template <typename FactoryT>
 void* operator()(FactoryT const& f, void * address) {
  return f.template apply<T>(address);
 }
};

int main() {
 int place;
 apply<int>()(factory(), &place);
 return 0;
}


Tries to instantiate structure `apply` instead of calling a `factory` member
function `apply` (prints error: invalid use of ‘struct apply<T>’).


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
@ 2012-12-03 16:01 ` redi at gcc dot gnu.org
  2012-12-03 16:08 ` paolo.carlini at oracle dot com
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-03 16:01 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-03 16:00:35 UTC ---
I don't think this is a G++ bug, there are three problems with this code:

1) You need to #include <new> to use placement new
2) factory::apply is non-const but the parameter 'f' is const
3) f.template apply<T> finds the current instantiation, ::apply<T>, rather than
the member function you are trying to call, use f.FactoryT::template apply<T>
instead


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
  2012-12-03 16:01 ` [Bug c++/55576] " redi at gcc dot gnu.org
@ 2012-12-03 16:08 ` paolo.carlini at oracle dot com
  2012-12-04  7:13 ` antoshkka at gmail dot com
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-12-03 16:08 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-12-03 16:08:31 UTC ---
Indeed. I also want to add that neither Icc 13, nor Oracle Solaris Studio 12.3,
nor Clang 3.0 accept it, whereas the code adjusted per Jon's points compiles
just fine with all of them.


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
  2012-12-03 16:01 ` [Bug c++/55576] " redi at gcc dot gnu.org
  2012-12-03 16:08 ` paolo.carlini at oracle dot com
@ 2012-12-04  7:13 ` antoshkka at gmail dot com
  2012-12-04  9:38 ` paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: antoshkka at gmail dot com @ 2012-12-04  7:13 UTC (permalink / raw)
  To: gcc-bugs


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

Antony Polukhin <antoshkka at gmail dot com> changed:

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

--- Comment #3 from Antony Polukhin <antoshkka at gmail dot com> 2012-12-04 07:12:12 UTC ---
(In reply to comment #1)
> I don't think this is a G++ bug, there are three problems with this code:
> 
> 1) You need to #include <new> to use placement new
> 2) factory::apply is non-const but the parameter 'f' is const

Fixed

> 3) f.template apply<T> finds the current instantiation, ::apply<T>, rather than
> the member function you are trying to call, use f.FactoryT::template apply<T>
> instead

That is the point. `f.template apply<T>(address);` is accepted by some
compilers without `FactoryT::`

Fixed version:

struct factory {
 template <typename T>
 void * apply(void * address) const {
  return 0;
 }
};

template <typename T>
struct apply {
 template <typename FactoryT>
 void* operator()(FactoryT const& f, void * address) const {
  return f.template apply<T>(address); // error: invalid use of ‘struct
apply<T>’ why???
 }
};

int main() {
 int place;
 apply<int>()(factory(), &place);
 return 0;
}


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (2 preceding siblings ...)
  2012-12-04  7:13 ` antoshkka at gmail dot com
@ 2012-12-04  9:38 ` paolo.carlini at oracle dot com
  2012-12-04 10:48 ` glisse at gcc dot gnu.org
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-12-04  9:38 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-12-04 09:37:44 UTC ---
.


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (3 preceding siblings ...)
  2012-12-04  9:38 ` paolo.carlini at oracle dot com
@ 2012-12-04 10:48 ` glisse at gcc dot gnu.org
  2012-12-04 11:05 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: glisse at gcc dot gnu.org @ 2012-12-04 10:48 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Marc Glisse <glisse at gcc dot gnu.org> 2012-12-04 10:47:38 UTC ---
For the example of comment #3, clang compiles it happily, and comeau gives this
message:

"ComeauTest.c", line 12: error: type name is not allowed
    return f.template apply<T>(address);
                      ^

"ComeauTest.c", line 12: warning: ambiguous class member reference -- function
          template "factory::apply" (declared at line 3) used in preference to
          type "apply<T>::apply [with T=int]" (declared at line 9)
    return f.template apply<T>(address);
                      ^
          detected during instantiation of "void *apply<T>::operator()(const
                    FactoryT &, void *) const [with T=int, FactoryT=factory]"
                    at line 18


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (4 preceding siblings ...)
  2012-12-04 10:48 ` glisse at gcc dot gnu.org
@ 2012-12-04 11:05 ` redi at gcc dot gnu.org
  2012-12-06 14:39 ` antoshkka at gmail dot com
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-04 11:05 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-04 11:04:45 UTC ---
I've been trying to find the relevant text in the standard but I'm not entirely
sure where this is covered. Possibly [temp.local] paras 3-5, including

"The injected-class-name of a class template or class template specialization
can be used either as a template-name or a type-name wherever it is in scope."


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (5 preceding siblings ...)
  2012-12-04 11:05 ` redi at gcc dot gnu.org
@ 2012-12-06 14:39 ` antoshkka at gmail dot com
  2012-12-06 15:47 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: antoshkka at gmail dot com @ 2012-12-06 14:39 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from Antony Polukhin <antoshkka at gmail dot com> 2012-12-06 14:39:39 UTC ---
(In reply to comment #6)
> "The injected-class-name of a class template or class template specialization
> can be used either as a template-name or a type-name wherever it is in scope."

So, shall we reopen this ticket?


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (6 preceding siblings ...)
  2012-12-06 14:39 ` antoshkka at gmail dot com
@ 2012-12-06 15:47 ` redi at gcc dot gnu.org
  2012-12-06 16:33 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-06 15:47 UTC (permalink / raw)
  To: gcc-bugs


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-06 15:46:59 UTC ---
Jason, could you have a look at the code in comment 3 and say whether the
lookup result is correct? thanks


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (7 preceding siblings ...)
  2012-12-06 15:47 ` redi at gcc dot gnu.org
@ 2012-12-06 16:33 ` jason at gcc dot gnu.org
  2012-12-13 18:02 ` tudorb at fb dot com
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2012-12-06 16:33 UTC (permalink / raw)
  To: gcc-bugs


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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |NEW
   Last reconfirmed|                            |2012-12-06
         Resolution|INVALID                     |
     Ever Confirmed|0                           |1

--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2012-12-06 16:33:09 UTC ---
3.4.5 seems clear on this point:

The identifier is first looked up in the class of the object expression. If the
identifier is not found, it is then looked up in the context of the entire
postfix-expression and shall name a class template.

So the testcase in comment 3 is valid.


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (8 preceding siblings ...)
  2012-12-06 16:33 ` jason at gcc dot gnu.org
@ 2012-12-13 18:02 ` tudorb at fb dot com
  2012-12-13 18:04 ` tudorb at fb dot com
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: tudorb at fb dot com @ 2012-12-13 18:02 UTC (permalink / raw)
  To: gcc-bugs


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

Tudor Bosman <tudorb at fb dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tudorb at fb dot com

--- Comment #10 from Tudor Bosman <tudorb at fb dot com> 2012-12-13 18:01:42 UTC ---
*** Bug 55668 has been marked as a duplicate of this bug. ***


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (9 preceding siblings ...)
  2012-12-13 18:02 ` tudorb at fb dot com
@ 2012-12-13 18:04 ` tudorb at fb dot com
  2013-02-25 14:07 ` potswa at mac dot com
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: tudorb at fb dot com @ 2012-12-13 18:04 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #11 from Tudor Bosman <tudorb at fb dot com> 2012-12-13 18:03:35 UTC ---
As I indicated in PR 55668, this has been broken since at least 4.1.2.


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (10 preceding siblings ...)
  2012-12-13 18:04 ` tudorb at fb dot com
@ 2013-02-25 14:07 ` potswa at mac dot com
  2013-02-25 16:20 ` d.frey at gmx dot de
  2013-03-16  9:45 ` paolo.carlini at oracle dot com
  13 siblings, 0 replies; 15+ messages in thread
From: potswa at mac dot com @ 2013-02-25 14:07 UTC (permalink / raw)
  To: gcc-bugs


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

David Krauss <potswa at mac dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |potswa at mac dot com

--- Comment #12 from David Krauss <potswa at mac dot com> 2013-02-25 14:06:30 UTC ---
Note, this is due to a C++11 change. Under C++03 there were additional rules in
3.4.5/1 rendering the code ill-formed. So it's not a coincidence this just
popped up recently.

Also, Clang compiles the example from comment 3.


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (11 preceding siblings ...)
  2013-02-25 14:07 ` potswa at mac dot com
@ 2013-02-25 16:20 ` d.frey at gmx dot de
  2013-03-16  9:45 ` paolo.carlini at oracle dot com
  13 siblings, 0 replies; 15+ messages in thread
From: d.frey at gmx dot de @ 2013-02-25 16:20 UTC (permalink / raw)
  To: gcc-bugs


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

Daniel Frey <d.frey at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |d.frey at gmx dot de

--- Comment #13 from Daniel Frey <d.frey at gmx dot de> 2013-02-25 16:20:20 UTC ---
Since it wasn't pointed out explicitly: The behaviour should depend on the
presence or absence of -std=c++0x/c++11/gnu++0x/gnu++11. The OPs example wasn't
compiled without any of these options, so it should be an error and GCC is
correct. With C++11 enabled, GCC's behaviour should be changed.


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

* [Bug c++/55576] Fails to compile a call to template member function
  2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
                   ` (12 preceding siblings ...)
  2013-02-25 16:20 ` d.frey at gmx dot de
@ 2013-03-16  9:45 ` paolo.carlini at oracle dot com
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-03-16  9:45 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |talljimbo at gmail dot com

--- Comment #14 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-03-16 09:45:38 UTC ---
*** Bug 56629 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2013-03-16  9:45 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-03 15:27 [Bug c++/55576] New: Fails to compile a call to template member function antoshkka at gmail dot com
2012-12-03 16:01 ` [Bug c++/55576] " redi at gcc dot gnu.org
2012-12-03 16:08 ` paolo.carlini at oracle dot com
2012-12-04  7:13 ` antoshkka at gmail dot com
2012-12-04  9:38 ` paolo.carlini at oracle dot com
2012-12-04 10:48 ` glisse at gcc dot gnu.org
2012-12-04 11:05 ` redi at gcc dot gnu.org
2012-12-06 14:39 ` antoshkka at gmail dot com
2012-12-06 15:47 ` redi at gcc dot gnu.org
2012-12-06 16:33 ` jason at gcc dot gnu.org
2012-12-13 18:02 ` tudorb at fb dot com
2012-12-13 18:04 ` tudorb at fb dot com
2013-02-25 14:07 ` potswa at mac dot com
2013-02-25 16:20 ` d.frey at gmx dot de
2013-03-16  9:45 ` 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).