public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54309] New: type alias accessing class template enum type member fails
@ 2012-08-18  5:16 paul at preney dot ca
  2012-08-18  6:02 ` [Bug c++/54309] [C++11] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: paul at preney dot ca @ 2012-08-18  5:16 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54309
           Summary: type alias accessing class template enum type member
                    fails
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: paul@preney.ca


Created attachment 28046
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28046
Source code demonstrating the bug.

This is easier to see not working than to describe. The code that does not work
(i.e., "not ok: BUG" comment in the example) works if you replace the using
type alias with a typedef instead though (which means that is a work-around for
now).

This bug was tested with these versions of GCC:

  g++ v4.7.0
  g++ v4.8.0 (snapshot 20120812)

The error message (from GCC v4.8):

$ g++-4.8.0-alpha20120812 -std=c++11 gcc-cxx-bug.cxx 
gcc-cxx-bug.cxx: In instantiation of ‘void func() [with T = int]’:
gcc-cxx-bug.cxx:25:13:   required from here
gcc-cxx-bug.cxx:15:24: error: no type named ‘Stuff’ in ‘using test = class
Foo<T>’
   typename test::Stuff b = test::Stuff::beta; // not ok: BUG
                        ^
gcc-cxx-bug.cxx:15:24: error: no type named ‘Stuff’ in ‘using test = class
Foo<T>’
gcc-cxx-bug.cxx:15:24: error: no type named ‘Stuff’ in ‘using test = class
Foo<T>’
$

(I also tried this code with clang++ (v3.1) and it compiles successfully as
expected.)


It appears to only occur when a using type alias (i.e., the "test" alias in the
example) is used to access a template class' member that is an enum type (i.e.,
"Foo<T>::Stuff" in the example) when the class template parameter is not
hard-coded using the using type alias (i.e., Foo<T> is used but Foo<int> is
okay). The code triggering the issue follows and is attached.


template <typename T>
class Foo
{
  public:
    enum class Stuff { alpha, beta };
};

template <typename T>
void func()
{
  typename Foo<T>::Stuff a = Foo<T>::Stuff::alpha; // ok
  a = a;

  using test = Foo<T>;
  typename test::Stuff b = test::Stuff::beta; // not ok: BUG
  b = b;

  typedef Foo<T> test2;
  typename test2::Stuff c = test2::Stuff::beta; // ok
  c = c;
}

int main()
{
  func<int>();

  {
    Foo<int>::Stuff a = Foo<int>::Stuff::alpha; // ok
    a = a;

    using test = Foo<int>;
    typename test::Stuff b = test::Stuff::beta; // ok
    b = b;

    typedef Foo<int> test2;
    typename test2::Stuff c = test2::Stuff::beta; // ok
    c = c;
  }
}


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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-18  5:16 [Bug c++/54309] New: type alias accessing class template enum type member fails paul at preney dot ca
2012-08-18  6:02 ` [Bug c++/54309] [C++11] " pinskia at gcc dot gnu.org
2012-08-18  6:05 ` [Bug c++/54309] [C++11] type alias accessing class template typename pinskia at gcc dot gnu.org
2012-08-18  9:40 ` paolo.carlini at oracle dot com
2012-08-20 12:10 ` dodji at seketeli dot org
2012-08-20 12:12 ` paolo.carlini at oracle dot com
2013-05-03  9:54 ` 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).