public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/22363] New: Problems with friend function injection and destructor @ 2005-07-08 11:09 cxl at ntllib dot org 2005-07-08 14:19 ` [Bug c++/22363] " bangerth at dealii dot org ` (3 more replies) 0 siblings, 4 replies; 6+ messages in thread From: cxl at ntllib dot org @ 2005-07-08 11:09 UTC (permalink / raw) To: gcc-bugs This code does not compile: template <class T> struct Feature { friend void AssertFeature0(T *) {} }; template <class T> inline void AssertFeature(T *t = 0) { if(t) AssertFeature0(t); } template <class T> struct Test : Feature< Test<T> > { int i; ~Test() { AssertFeature<T>(); } }; struct Foo : Feature<Foo> { int x; }; void foo() { Test< Test<Foo> > test; } ---------------------- The problem seems to be in fact that ~Test destructor is instantiated BEFORE friend is injected and only in the case that templates are nested. Moving AssertFeature to other method (and instatiating) or reducing test-case to just "Test<Foo> test;" makes code compile fine. Comeau C++ testdrive compiles this code without problems. -- Summary: Problems with friend function injection and destructor Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: cxl at ntllib dot org CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22363 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/22363] Problems with friend function injection and destructor 2005-07-08 11:09 [Bug c++/22363] New: Problems with friend function injection and destructor cxl at ntllib dot org @ 2005-07-08 14:19 ` bangerth at dealii dot org 2005-07-08 14:26 ` pinskia at gcc dot gnu dot org ` (2 subsequent siblings) 3 siblings, 0 replies; 6+ messages in thread From: bangerth at dealii dot org @ 2005-07-08 14:19 UTC (permalink / raw) To: gcc-bugs ------- Additional Comments From bangerth at dealii dot org 2005-07-08 14:19 ------- *** Bug 22364 has been marked as a duplicate of this bug. *** -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22363 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/22363] Problems with friend function injection and destructor 2005-07-08 11:09 [Bug c++/22363] New: Problems with friend function injection and destructor cxl at ntllib dot org 2005-07-08 14:19 ` [Bug c++/22363] " bangerth at dealii dot org @ 2005-07-08 14:26 ` pinskia at gcc dot gnu dot org 2005-07-08 14:59 ` bangerth at dealii dot org 2005-09-30 5:12 ` pinskia at gcc dot gnu dot org 3 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu dot org @ 2005-07-08 14:26 UTC (permalink / raw) To: gcc-bugs -- What |Removed |Added ---------------------------------------------------------------------------- Keywords| |rejects-valid Known to fail| |2.95.3 3.2.3 3.3.3 3.4.0 | |4.0.0 3.0.4 4.1.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22363 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/22363] Problems with friend function injection and destructor 2005-07-08 11:09 [Bug c++/22363] New: Problems with friend function injection and destructor cxl at ntllib dot org 2005-07-08 14:19 ` [Bug c++/22363] " bangerth at dealii dot org 2005-07-08 14:26 ` pinskia at gcc dot gnu dot org @ 2005-07-08 14:59 ` bangerth at dealii dot org 2005-09-30 5:12 ` pinskia at gcc dot gnu dot org 3 siblings, 0 replies; 6+ messages in thread From: bangerth at dealii dot org @ 2005-07-08 14:59 UTC (permalink / raw) To: gcc-bugs ------- Additional Comments From bangerth at dealii dot org 2005-07-08 14:58 ------- I don't quite know what to say, whether this is a bug or not. Take this reduced snippet: --------------------------- template <class T> struct S { friend void foo(T *); }; template <class T> void bar() { foo((T*)0); } template <class T> struct X : S< X<T> > { X() { bar<T>(); } }; X< X<int> > test; ---------------------------- icc compiles this, but gcc doesn't, with this error message: g/x> /home/bangerth/bin/gcc-4.1*/bin/c++ -c x.cc x.cc:2: warning: friend declaration ‘void foo(T*)’ declares a non-template function x.cc:2: warning: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning x.cc: In function ‘void bar() [with T = X<int>]’: x.cc:10: instantiated from ‘X<T>::X() [with T = X<int>]’ x.cc:13: instantiated from here x.cc:5: error: cannot convert ‘X<int>*’ to ‘X<X<int> >*’ for argument ‘1’ to ‘void foo(X<X<int> >*)’ What is happening is that in the definition of 'test', we instantiate X<X<int> >, which through its derivation from S<X<X<int>>> makes sure that there is a function foo<X<X<int>>> (that this function is available is visible from the error message). However, in the destructor of X<X<int>>, we call bar<X<int>> which in turn wants to call foo<X<int>>, which doesn't exist. I believe that the reason why icc can compile this is that in the definition of 'test', the compiler does not only instantiate X<X<int>>, but also X<int>. If that were the case, then we would have a function foo<X<int>> from that instantiation, available for use when we get to instantiate the destructor of X<X<int>>. The question is: do we need to instantiate X<int> in order to instantiate X<X<int>>? (Here's a sidenote: apparently, icc only instantiates the *type* X<int>, but not the destructor X<int>::~X. I can infer this because if it did, then it would want to call bar<int> which in turn would want to call foo<int>; that one, however, doesn't exist...) W. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22363 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/22363] Problems with friend function injection and destructor 2005-07-08 11:09 [Bug c++/22363] New: Problems with friend function injection and destructor cxl at ntllib dot org ` (2 preceding siblings ...) 2005-07-08 14:59 ` bangerth at dealii dot org @ 2005-09-30 5:12 ` pinskia at gcc dot gnu dot org 3 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu dot org @ 2005-09-30 5:12 UTC (permalink / raw) To: gcc-bugs [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 784 bytes --] ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-09-30 05:12 ------- For the testcase in comment #2, on the mainline, we get a different error message: t.cc:2: warning: friend declaration void foo(T*) declares a non-template function t.cc:2: warning: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning t.cc: In function void bar() [with T = X<int>]: t.cc:10: instantiated from X<T>::X() [with T = X<int>] t.cc:13: instantiated from here t.cc:5: error: foo was not declared in this scope This seems better as friend don't intject the declation at all. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22363 ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <bug-22363-7316@http.gcc.gnu.org/bugzilla/>]
* [Bug c++/22363] Problems with friend function injection and destructor [not found] <bug-22363-7316@http.gcc.gnu.org/bugzilla/> @ 2006-10-21 20:23 ` pinskia at gcc dot gnu dot org 0 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu dot org @ 2006-10-21 20:23 UTC (permalink / raw) To: gcc-bugs ------- Comment #4 from pinskia at gcc dot gnu dot org 2006-10-21 20:23 ------- (In reply to comment #3) > For the testcase in comment #2, on the mainline, we get a different error > message: That is the correct error so closing as fixed for 4.2.0 as friends don't inject at all. -- pinskia at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |FIXED Target Milestone|--- |4.2.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22363 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-10-21 20:23 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-07-08 11:09 [Bug c++/22363] New: Problems with friend function injection and destructor cxl at ntllib dot org 2005-07-08 14:19 ` [Bug c++/22363] " bangerth at dealii dot org 2005-07-08 14:26 ` pinskia at gcc dot gnu dot org 2005-07-08 14:59 ` bangerth at dealii dot org 2005-09-30 5:12 ` pinskia at gcc dot gnu dot org [not found] <bug-22363-7316@http.gcc.gnu.org/bugzilla/> 2006-10-21 20:23 ` pinskia at gcc dot gnu 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).