public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59383] New: typedef propagation with template base class using the same name is wrong
@ 2013-12-04 13:07 gmarkhor at gmail dot com
  2014-12-18 10:10 ` [Bug c++/59383] " naup at sfr dot fr
  2021-12-07 11:42 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: gmarkhor at gmail dot com @ 2013-12-04 13:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59383
           Summary: typedef propagation with template base class using the
                    same name is wrong
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gmarkhor at gmail dot com

I am using g++ 4.8.1. Consider the following code (compiled as g++ -std=c++11
-c test.cc):

#include <type_traits>

template <typename F, typename S>
struct TypePair {
  typedef F First;
  typedef S Second;
};

template <int I>
class Base {
 public:
  typedef TypePair<Base, Base> Family;
  typedef Base ParentType;
};

template <int I>
class Derived : public Base<I> {
 public:
  typedef TypePair<Derived, typename Derived::Family::First> Family;
  typedef typename Family::Second ParentType;
};

static_assert(std::is_same<Base<1>, Derived<1>::ParentType>::value, "Error");




The static assertion is failed. Clang ver. 3.2 and 3.3 and 3.4 compiles this
code well.

If you remove the template from Base:




#include <type_traits>

template <typename F, typename S>
struct TypePair {
  typedef F First;
  typedef S Second;
};

class Base {
 public:
  typedef TypePair<Base, Base> Family;
  typedef Base ParentType;
};

template <int I>
class Derived : public Base {
 public:
  typedef TypePair<Derived, typename Derived::Family::First> Family;
  typedef typename Family::Second ParentType;
};

static_assert(std::is_same<Base, Derived<1>::ParentType>::value, "Error");




then everything becomes OK. The other way to make it work is to remove template
from Derived and inherit from an explicit Base<1>:





#include <type_traits>

template <typename F, typename S>
struct TypePair {
  typedef F First;
  typedef S Second;
};

template <int I>
class Base {
 public:
  typedef TypePair<Base, Base> Family;
  typedef Base ParentType;
};

class Derived : public Base<1> {
 public:
  typedef TypePair<Derived, typename Derived::Family::First> Family;
  typedef typename Family::Second ParentType;
};

static_assert(std::is_same<Base<1>, Derived::ParentType>::value, "Error");



I am not sure what standard says about this, but it seems a bug.


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

* [Bug c++/59383] typedef propagation with template base class using the same name is wrong
  2013-12-04 13:07 [Bug c++/59383] New: typedef propagation with template base class using the same name is wrong gmarkhor at gmail dot com
@ 2014-12-18 10:10 ` naup at sfr dot fr
  2021-12-07 11:42 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: naup at sfr dot fr @ 2014-12-18 10:10 UTC (permalink / raw)
  To: gcc-bugs

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

naup at sfr dot fr changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |naup at sfr dot fr

--- Comment #1 from naup at sfr dot fr ---
This is the same behaviour as in invalid bug 50418.

Alas, no diagnostic is required, says the standard, and gcc interpretes
**differently** the typedef type wheither the base is template or not.

NON TEMPLATE BASE
struct A
{
   typedef A this_type;
}; 
template <class T> struct B : public A
{
   typedef this_type parent;  // this_type is taken as **A** (current context)
   typedef B this_type;       // the two lines make B ill-formed
}; 

TEMPLATE BASE
template <class T> struct A
{
   typedef A this_type;
}; 
template <class T> struct B : public A<T>
{
   typedef this_type parent;  // this_type is taken as **B** (after-next-line
context)
   typedef B this_type;       // the two lines make B ill-formed
};


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

* [Bug c++/59383] typedef propagation with template base class using the same name is wrong
  2013-12-04 13:07 [Bug c++/59383] New: typedef propagation with template base class using the same name is wrong gmarkhor at gmail dot com
  2014-12-18 10:10 ` [Bug c++/59383] " naup at sfr dot fr
@ 2021-12-07 11:42 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-07 11:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Invalid as explained.

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

end of thread, other threads:[~2021-12-07 11:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-04 13:07 [Bug c++/59383] New: typedef propagation with template base class using the same name is wrong gmarkhor at gmail dot com
2014-12-18 10:10 ` [Bug c++/59383] " naup at sfr dot fr
2021-12-07 11:42 ` 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).