public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54875] New: Forward declare enums cannot be used as a template argument
@ 2012-10-09 13:39 public at alisdairm dot net
  2012-10-09 14:23 ` [Bug c++/54875] " daniel.kruegler at googlemail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: public at alisdairm dot net @ 2012-10-09 13:39 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54875
           Summary: Forward declare enums cannot be used as a template
                    argument
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: public@alisdairm.net


The following simple code snippet shows the problem:

template<typename T>
using AddConst = T const;

enum FwdEnum : int;

int main() {
   AddConst<FwdEnum> *ptr = nullptr;
}


Trying to instantiate the alias template, in this case to declare a pointer but
the problem is more general, produces an internal compiler error.  The problem
is probably older than the gcc 4.8 I am testing with, but it does give a nice
assertion from the compiler:


main.cpp: In function 'int main()':
main.cpp:7:20: internal compiler error: tree check: expected enumeral_type,
have template_type_parm in tsubst_enum, at cp/pt.c:18923
    AddConst<FwdEnum> *ptr = nullptr;
                    ^

main.cpp:7:20: internal compiler error: Abort trap: 6
g++-mp-4.8: internal compiler error: Abort trap: 6 (program cc1plus)
Abort trap: 6


Version info of the compiler I am testing with:
gcc -v -save-temps -std=c++11

Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~28/src/configure
--disable-checking --enable-werror
--prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2
--mandir=/share/man --enable-languages=c,objc,c++,obj-c++
--program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/
--with-slibdir=/usr/lib --build=i686-apple-darwin11
--enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~28/dst-llvmCore/Developer/usr/local
--program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11
--target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)


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

* [Bug c++/54875] Forward declare enums cannot be used as a template argument
  2012-10-09 13:39 [Bug c++/54875] New: Forward declare enums cannot be used as a template argument public at alisdairm dot net
@ 2012-10-09 14:23 ` daniel.kruegler at googlemail dot com
  2012-10-09 14:38 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-10-09 14:23 UTC (permalink / raw)
  To: gcc-bugs


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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-10-09 14:23:36 UTC ---
I can reproduce this error with gcc 4.8.0 20120930 (experimental), were I get:

"main.cpp|7|internal compiler error: tree check: expected enumeral_type, have
template_type_parm in tsubst_enum, at cp/pt.c:18886|"

[Note the slight difference in the source code line number]


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

* [Bug c++/54875] Forward declare enums cannot be used as a template argument
  2012-10-09 13:39 [Bug c++/54875] New: Forward declare enums cannot be used as a template argument public at alisdairm dot net
  2012-10-09 14:23 ` [Bug c++/54875] " daniel.kruegler at googlemail dot com
@ 2012-10-09 14:38 ` paolo.carlini at oracle dot com
  2012-10-26 18:50 ` dodji at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-09 14:38 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-10-09 14:38:06 UTC ---
As far as I can see, the alias declaration is essential. As such, let's add
Dodji in CC, maybe he can have a look.


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

* [Bug c++/54875] Forward declare enums cannot be used as a template argument
  2012-10-09 13:39 [Bug c++/54875] New: Forward declare enums cannot be used as a template argument public at alisdairm dot net
  2012-10-09 14:23 ` [Bug c++/54875] " daniel.kruegler at googlemail dot com
  2012-10-09 14:38 ` paolo.carlini at oracle dot com
@ 2012-10-26 18:50 ` dodji at gcc dot gnu.org
  2012-11-16 12:57 ` dodji at seketeli dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dodji at gcc dot gnu.org @ 2012-10-26 18:50 UTC (permalink / raw)
  To: gcc-bugs


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

Dodji Seketeli <dodji at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-10-26
         AssignedTo|unassigned at gcc dot       |dodji at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug c++/54875] Forward declare enums cannot be used as a template argument
  2012-10-09 13:39 [Bug c++/54875] New: Forward declare enums cannot be used as a template argument public at alisdairm dot net
                   ` (2 preceding siblings ...)
  2012-10-26 18:50 ` dodji at gcc dot gnu.org
@ 2012-11-16 12:57 ` dodji at seketeli dot org
  2012-11-16 15:20 ` dodji at gcc dot gnu.org
  2012-11-16 15:23 ` dodji at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: dodji at seketeli dot org @ 2012-11-16 12:57 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from dodji at seketeli dot org <dodji at seketeli dot org> 2012-11-16 12:57:37 UTC ---
I candidate patchlet has been submitted for this at
http://gcc.gnu.org/ml/gcc-patches/2012-11/msg01375.html.


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

* [Bug c++/54875] Forward declare enums cannot be used as a template argument
  2012-10-09 13:39 [Bug c++/54875] New: Forward declare enums cannot be used as a template argument public at alisdairm dot net
                   ` (3 preceding siblings ...)
  2012-11-16 12:57 ` dodji at seketeli dot org
@ 2012-11-16 15:20 ` dodji at gcc dot gnu.org
  2012-11-16 15:23 ` dodji at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: dodji at gcc dot gnu.org @ 2012-11-16 15:20 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from Dodji Seketeli <dodji at gcc dot gnu.org> 2012-11-16 15:20:11 UTC ---
Author: dodji
Date: Fri Nov 16 15:20:03 2012
New Revision: 193562

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193562
Log:
PR c++/54875 -  Error with alias template that resolves to an enum

Consider this short example:

     1    template<typename T>
     2    using AddConst = T const;
     3
     4    enum FwdEnum : int;
     5
     6    int main() {
     7      AddConst<FwdEnum> *ptr = nullptr;
     8    }

At line 7, when we build the type for AddConst<FwdEnum> in
lookup_template_class_1, the resulting type is the enum FwdEnum.  This
confuses lookup_template_class_1 near the if below, wrongly making it
taking the branch and thus calling tsubst_enum while it shouldn't:

      if (TREE_CODE (t) == ENUMERAL_TYPE && !is_dependent_type)
    /* Now that the type has been registered on the instantiations
       list, we set up the enumerators.  Because the enumeration
       constants may involve the enumeration type itself, we make
       sure to register the type first, and then create the
       constants.  That way, doing tsubst_expr for the enumeration
       constants won't result in recursive calls here; we'll find
       the instantiation and exit above.  */
    tsubst_enum (template_type, t, arglist);

Before the alias template feature, the only reason why TREE_CODE (t)
== ENUMERAL_TYPE would be true is when lookup_template_class_1 is
called for an enum that is a member of a class template.  But that
condition can be also true for an alias template instantiation.

So I guess that condition should be changed to TREE_CODE
(template_type) == ENUMERAL_TYPE, to specifically detect the member
enum of a class template case.  Note that for the alias template
instantiation case above, template_type points to a TEMPLATE_TYPE_PARM
which name is AddConst.

This is what the patchlet below does.

Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.

gcc/cp/

    * pt.c (lookup_template_class_1): Look at the type of the
    potential member enum of class template to determine if we are
    actually substituting into a member enum of class template.

gcc/testsuite/

    * g++.dg/cpp0x/alias-decl-27.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/alias-decl-27.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/54875] Forward declare enums cannot be used as a template argument
  2012-10-09 13:39 [Bug c++/54875] New: Forward declare enums cannot be used as a template argument public at alisdairm dot net
                   ` (4 preceding siblings ...)
  2012-11-16 15:20 ` dodji at gcc dot gnu.org
@ 2012-11-16 15:23 ` dodji at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: dodji at gcc dot gnu.org @ 2012-11-16 15:23 UTC (permalink / raw)
  To: gcc-bugs


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

Dodji Seketeli <dodji at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #5 from Dodji Seketeli <dodji at gcc dot gnu.org> 2012-11-16 15:23:41 UTC ---
Fixed in trunk (4.8)


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

end of thread, other threads:[~2012-11-16 15:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-09 13:39 [Bug c++/54875] New: Forward declare enums cannot be used as a template argument public at alisdairm dot net
2012-10-09 14:23 ` [Bug c++/54875] " daniel.kruegler at googlemail dot com
2012-10-09 14:38 ` paolo.carlini at oracle dot com
2012-10-26 18:50 ` dodji at gcc dot gnu.org
2012-11-16 12:57 ` dodji at seketeli dot org
2012-11-16 15:20 ` dodji at gcc dot gnu.org
2012-11-16 15:23 ` dodji 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).