public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class
@ 2012-11-22  4:07 conradsand.arma at gmail dot com
  2012-11-22  4:14 ` [Bug c++/55436] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: conradsand.arma at gmail dot com @ 2012-11-22  4:07 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55436
           Summary: g++ compiles invalid code with child class of nested
                    class in template class
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: conradsand.arma@gmail.com


Created attachment 28760
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28760
test.cpp: source for invalid code that compiles under g++

The code below compiles under g++ 4.7.2 and 4.4.6, but is apparently invalid,
ie. it is not rejected by g++.

We initially thought this was a bug in the clang compiler, but the clang folks
are saying that this is a bug in g++ (ie. gcc shouldn't be accepting this
code).

Related clang bugzilla bug entry:
http://llvm.org/bugs/show_bug.cgi?id=14402

The clang folks are quoting this part of the standard:

See [temp.dep]p3: "In the definition of a class or class template, if a base
class depends on a template-parameter, the base class scope is not examined
during unqualified name lookup either at the point of definition of the class
template or member or during an instantiation of the class template or member."

#include <iostream>

template<typename T>
class A
{
 public:
  void m() { std::cout << "A::m()" << std::endl; }
  void z() { m(); }

  class B
  {
   public:
    void m() { std::cout << "B::m()" << std::endl; }
    void y() { m(); }
  };

  class C : public B
  {
   public:
    void x() { m(); }
  };
};

int main()
{
  A<double> a;
  a.z();

  A<double>::B b;
  b.y();

  A<double>::C c;
  c.x();
}


Clang 3.1 reports the following error:
test.cpp:20:16: error: call to non-static member function 'm' of 'A' from
nested
      type 'C'
    void x() { m(); }


Shouldn't g++ also report a similar error?


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
@ 2012-11-22  4:14 ` pinskia at gcc dot gnu.org
  2012-11-22 12:54 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-11-22  4:14 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-11-22 04:13:58 UTC ---
Comeau online tester (which is EDG based) says:
"ComeauTest.c", line 20: error: a nonstatic member reference must be relative
to a
          specific object
      void x() { m(); }
                 ^
          detected during instantiation of "void A<T>::C::x() [with T=double]"
                    at line 33


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
  2012-11-22  4:14 ` [Bug c++/55436] " pinskia at gcc dot gnu.org
@ 2012-11-22 12:54 ` redi at gcc dot gnu.org
  2012-11-22 12:58 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-22 12:54 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-11-22
     Ever Confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-22 12:53:54 UTC ---
Yes, A<T>::B is a dependent base of A<T>::C, so lookup should find A::m not
B::m


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
  2012-11-22  4:14 ` [Bug c++/55436] " pinskia at gcc dot gnu.org
  2012-11-22 12:54 ` redi at gcc dot gnu.org
@ 2012-11-22 12:58 ` redi at gcc dot gnu.org
  2012-12-18  8:55 ` conradsand.arma at gmail dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-22 12:58 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid, wrong-code

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-22 12:58:19 UTC ---
This is also a wrong-code and rejects-valid bug.

This correct program shows the wrong m() being called (and so results in a
linker error)


template<typename T>
struct A
{
  static void m() { }

  struct B
  {
    void m();
  };

  struct C : B
  {
    void x() { m(); }
  };
};

int main()
{
  A<double>::C c;
  c.x();
}

and if we make B::m private we get rejects-valid

.cc: In member function ‘void A<T>::C::x() [with T = double]’:
x.cc:21:7:   instantiated from here
x.cc:9:10: error: ‘void A<T>::B::m() [with T = double]’ is private
x.cc:14:16: error: within this context


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
                   ` (2 preceding siblings ...)
  2012-11-22 12:58 ` redi at gcc dot gnu.org
@ 2012-12-18  8:55 ` conradsand.arma at gmail dot com
  2012-12-18 10:47 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: conradsand.arma at gmail dot com @ 2012-12-18  8:55 UTC (permalink / raw)
  To: gcc-bugs


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

Conrad <conradsand.arma at gmail dot com> changed:

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

--- Comment #4 from Conrad <conradsand.arma at gmail dot com> 2012-12-18 08:55:23 UTC ---
Compiling the invalid test.cpp (original attachment) under 4.8.0 20121209
(x86_64) also works, when it shouldn't.

The code presented in Comment #3 by Jonathan Wakely also results in a linked
error when using 4.8.0 20121209.

Should this bug be upgraded to P2, given its wide ranging effects ?


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
                   ` (3 preceding siblings ...)
  2012-12-18  8:55 ` conradsand.arma at gmail dot com
@ 2012-12-18 10:47 ` redi at gcc dot gnu.org
  2012-12-18 14:55 ` conradsand.arma at gmail dot com
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-18 10:47 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-18 10:46:57 UTC ---
(In reply to comment #4)
> Should this bug be upgraded to P2, given its wide ranging effects ?

If it was a serious problem it would have been reported before by more people.


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
                   ` (4 preceding siblings ...)
  2012-12-18 10:47 ` redi at gcc dot gnu.org
@ 2012-12-18 14:55 ` conradsand.arma at gmail dot com
  2012-12-18 15:30 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: conradsand.arma at gmail dot com @ 2012-12-18 14:55 UTC (permalink / raw)
  To: gcc-bugs


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

Conrad <conradsand.arma at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|4.7.2                       |4.8.0

--- Comment #6 from Conrad <conradsand.arma at gmail dot com> 2012-12-18 14:54:50 UTC ---
> If it was a serious problem it would have been reported before by more people.

I'm not sure if the degree of popularity of a bug should diminish its
seriousness.  This is an "accepts-invalid, rejects-valid, wrong-code" bug,
which is pretty nasty as far as bugs go. The use of C++ is expanding (including
GCC's own code base), meaning this bug is going to bite more people as time
goes on.

However, I do understand that bugs which affect more people right now should
get looked at first. Furthermore, given its wide ranging impact, perhaps fixing
this bug in 4.7.x would not be doable (ie. too invasive).  As such, I'll
reassign this bug to 4.8.0.


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
                   ` (5 preceding siblings ...)
  2012-12-18 14:55 ` conradsand.arma at gmail dot com
@ 2012-12-18 15:30 ` redi at gcc dot gnu.org
  2013-01-09  6:03 ` conradsand.arma at gmail dot com
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-18 15:30 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-18 15:29:59 UTC ---
(In reply to comment #6)
> > If it was a serious problem it would have been reported before by more people.
> 
> I'm not sure if the degree of popularity of a bug should diminish its
> seriousness.

If noone else has ever reported it in all the time it's been in GCC it's not
causing a lot of problems, then it's not causing serious problems to most GCC
users.  It's not a regression and there's a workaround (qualify the names) so
it's not P2.

>  This is an "accepts-invalid, rejects-valid, wrong-code" bug,
> which is pretty nasty as far as bugs go.

Almost any name lookup bug can be turned into all three categories, it doesn't
alter its seriousness.

> The use of C++ is expanding (including
> GCC's own code base), meaning this bug is going to bite more people as time
> goes on.

It will get fixed, it doesn't need to be P2 for that.


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
                   ` (6 preceding siblings ...)
  2012-12-18 15:30 ` redi at gcc dot gnu.org
@ 2013-01-09  6:03 ` conradsand.arma at gmail dot com
  2013-10-12  3:19 ` conradsand.arma at gmail dot com
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: conradsand.arma at gmail dot com @ 2013-01-09  6:03 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #8 from Conrad <conradsand.arma at gmail dot com> 2013-01-09 06:03:07 UTC ---
Can we change this bug status to _confirmed_, and the target milestone to 4.8.0
?


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
                   ` (7 preceding siblings ...)
  2013-01-09  6:03 ` conradsand.arma at gmail dot com
@ 2013-10-12  3:19 ` conradsand.arma at gmail dot com
  2013-10-12 15:14 ` paolo.carlini at oracle dot com
  2021-07-27  0:28 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: conradsand.arma at gmail dot com @ 2013-10-12  3:19 UTC (permalink / raw)
  To: gcc-bugs

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

Conrad <conradsand.arma at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |conradsand.arma at gmail dot com

--- Comment #9 from Conrad <conradsand.arma at gmail dot com> ---
Paolo, any reason for twice removing my address from the CC list for this bug?


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
                   ` (8 preceding siblings ...)
  2013-10-12  3:19 ` conradsand.arma at gmail dot com
@ 2013-10-12 15:14 ` paolo.carlini at oracle dot com
  2021-07-27  0:28 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-12 15:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|conradsand.arma at gmail dot com   |

--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Yes, it's redundant, you get all the messages by default being the bug
submitter


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

* [Bug c++/55436] g++ compiles invalid code with child class of nested class in template class
  2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
                   ` (9 preceding siblings ...)
  2013-10-12 15:14 ` paolo.carlini at oracle dot com
@ 2021-07-27  0:28 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27  0:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55436

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |7.0
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=10200,
                   |                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=69753

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 7 by r7-755.

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

end of thread, other threads:[~2021-07-27  0:28 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22  4:07 [Bug c++/55436] New: g++ compiles invalid code with child class of nested class in template class conradsand.arma at gmail dot com
2012-11-22  4:14 ` [Bug c++/55436] " pinskia at gcc dot gnu.org
2012-11-22 12:54 ` redi at gcc dot gnu.org
2012-11-22 12:58 ` redi at gcc dot gnu.org
2012-12-18  8:55 ` conradsand.arma at gmail dot com
2012-12-18 10:47 ` redi at gcc dot gnu.org
2012-12-18 14:55 ` conradsand.arma at gmail dot com
2012-12-18 15:30 ` redi at gcc dot gnu.org
2013-01-09  6:03 ` conradsand.arma at gmail dot com
2013-10-12  3:19 ` conradsand.arma at gmail dot com
2013-10-12 15:14 ` paolo.carlini at oracle dot com
2021-07-27  0:28 ` pinskia at gcc dot gnu.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).