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

             Bug #: 55708
           Summary: g++ crashes: constexpr function with reference
                    parameters.
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: lundb...@gmail.com


The following code crashes g++ 4.8-20121209 (and gcc 4.7.2). The issue occurs
with some uses of the result of a constexpr function with reference parameters
(&& or &). 

Both the normal template do_y() and user defoned literal _y() shows exactly the
same problem, via the assert at cp/pt.c:14334. 

Perhaps related: bug 49514, http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49514

Full example:

template<int N,int NNN>
struct AA { static constexpr int val = N; };

template<typename A,typename B>
//constexpr unsigned long long mymax(A a,B b){ // <-- compiles 
constexpr unsigned long long mymax(A && a,const B& b){
  return a<b?b:a;
}

template<char... List>
constexpr long long operator"" _y() noexcept
{
  return AA<1, mymax(1,2)>::val; // <-- crashes gcc
  // return mymax(1,2);   // <-- compiles
  // return AA<1,2>::val; // <-- compiles
}

template<char... List>
constexpr unsigned long long do_y() noexcept
{
  return AA<1, mymax(1,2)>::val; <-- crashes gcc
}

int main(){
  return 1_y + do_y() ;  
}

I compiled with g++ -Wall -Wextra file.cpp -std=c++11
Here's the full g++ printout:

In function ‘constexpr long long int operator"" _y()’:
internal compiler error: in tsubst_copy_and_build, at cp/pt.c:14334
   return AA<1, mymax(1,2)>::val;
                         ^
0x81a4dc9 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
    ../.././gcc/cp/pt.c:14334
0x81ed922 tsubst_non_call_postfix_expression
    ../.././gcc/cp/pt.c:13229
0x81a0422 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
    ../.././gcc/cp/pt.c:13452
0x81a0a99 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
    ../.././gcc/cp/pt.c:13352
0x81a1439 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
    ../.././gcc/cp/pt.c:13760
0x81a5c3a fold_non_dependent_expr_sfinae(tree_node*, int)
    ../.././gcc/cp/pt.c:5081
0x81c48bd convert_nontype_argument
    ../.././gcc/cp/pt.c:5493
0x81c48bd convert_template_argument
    ../.././gcc/cp/pt.c:6383
0x81ca30b coerce_template_parms
    ../.././gcc/cp/pt.c:6722
0x81cc506 lookup_template_class_1
    ../.././gcc/cp/pt.c:7226
0x81cc506 lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
    ../.././gcc/cp/pt.c:7523
0x82dbc87 finish_template_type(tree_node*, tree_node*, int)
    ../.././gcc/cp/semantics.c:2791
0x8267f40 cp_parser_template_id
    ../.././gcc/cp/parser.c:12707
0x826834a cp_parser_class_name
    ../.././gcc/cp/parser.c:18105
0x825cf49 cp_parser_qualifying_entity
    ../.././gcc/cp/parser.c:5276
0x825cf49 cp_parser_nested_name_specifier_opt
    ../.././gcc/cp/parser.c:5007
0x8275975 cp_parser_simple_type_specifier
    ../.././gcc/cp/parser.c:13882
0x825be2a cp_parser_postfix_expression
    ../.././gcc/cp/parser.c:5551
0x825e5ab cp_parser_unary_expression
    ../.././gcc/cp/parser.c:6686
0x825f185 cp_parser_binary_expression
    ../.././gcc/cp/parser.c:7360

Reply via email to