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

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
So I have

--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -27969,6 +27969,13 @@ value_dependent_expression_p (tree expression)
       else if (TYPE_REF_P (TREE_TYPE (expression)))
    /* FIXME cp_finish_decl doesn't fold reference initializers.  */
    return true;
+      /* We have a constexpr variable and we're processing a template.  When
+    there's lifetime extension involved (for which finish_compound_literal
+    used to create a temporary), we'll not be able to evaluate the
+    variable until instantiating, so pretend it's value-dependent.  */
+      else if (DECL_DECLARED_CONSTEXPR_P (expression)
+          && !TREE_CONSTANT (expression))
+   return true;
       return false;

     case DYNAMIC_CAST_EXPR:

but that breaks

struct foo {  };

template <const foo & F> void fnc() { } 

void
test()
{
  static constexpr foo a;
  fnc<a>();
}

with:

$ ./cc1plus -quiet nontype-auto16.C 
nontype-auto16.C:6:31: warning: ‘void fnc() [with const foo& F = a]’ used but
never defined
    6 | template <const foo & F> void fnc() { }
      |                               ^~~
nontype-auto16.C:13:1: internal compiler error: Segmentation fault
   13 | }
      | ^
0x19a5624 crash_signal
        /home/mpolacek/src/gcc/gcc/toplev.cc:314
0x7fe161facb1f ???
       
/usr/src/debug/glibc-2.36-9.fc37.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xcbfe74 tree_check(tree_node const*, char const*, int, char const*, tree_code)
        /home/mpolacek/src/gcc/gcc/tree.h:3795
0x12c2224 symbol_table::decl_assembler_name_hash(tree_node const*)
        /home/mpolacek/src/gcc/gcc/symtab.cc:84

The warning is obviously wrong and the cause for the ICE, I'd say.  test isn't
a function template but uses_template_parms / verify_unstripped_args set p_t_d,
so we still reach the new code.

Reply via email to