This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/70642] New: Invalid alias template instantiation not rejected if previously used in SFINAE context


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

            Bug ID: 70642
           Summary: Invalid alias template instantiation not rejected if
                    previously used in SFINAE context
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com
  Target Milestone: ---

Reduced from http://stackoverflow.com/q/36578055/2756719.

The following ill-formed code is incorrectly accepted by GCC:

template<bool, class> struct enable_if {};
template<class T> struct enable_if<true, T> { using type = T; };

template <typename X>
struct foo
{
     template <typename R>
     using meow = typename enable_if<sizeof(X) == 0, R>::type;

     template <typename R = int>       // 1
     meow<R> bar () = delete;

     int bar ()
     {
        meow<int> i;          // 2
        return 0;             // 3
     }
};

int j = foo<long>().bar();

Attempting to use i (by changing line #3 to 'return i;') causes an ICE:

prog.cc: In instantiation of 'int foo<X>::bar() [with X = long int]':
prog.cc:20:25:   required from here
prog.cc:16:16: internal compiler error: in tsubst_copy, at cp/pt.c:14043
         return i;
                ^
0x6019dd tsubst_copy
        /home/heads/gcc/gcc-source/gcc/cp/pt.c:14041
0x602021 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        /home/heads/gcc/gcc-source/gcc/cp/pt.c:16993
0x5fdcd8 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/heads/gcc/gcc-source/gcc/cp/pt.c:15802
0x5fda06 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/heads/gcc/gcc-source/gcc/cp/pt.c:15114
0x5fd454 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/heads/gcc/gcc-source/gcc/cp/pt.c:15104
0x5fdb73 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/heads/gcc/gcc-source/gcc/cp/pt.c:15290
0x5fc36f instantiate_decl(tree_node*, int, bool)
        /home/heads/gcc/gcc-source/gcc/cp/pt.c:22014
0x618c8b instantiate_pending_templates(int)
        /home/heads/gcc/gcc-source/gcc/cp/pt.c:22131
0x636eed c_parse_final_cleanups()
        /home/heads/gcc/gcc-source/gcc/cp/decl2.c:4599
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

The problem appears to only arise if the types in Lines #1 and #2 match (i.e.,
when the alias template has been instantiated in a SFINAE context already); if
either (but not both) is changed to, e.g., void, or if the first bar() overload
is removed, then the error is correctly diagnosed.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]