[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-22 Thread edlinger at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

Bernd Edlinger  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from Bernd Edlinger  ---
fixed on trunk.

[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-22 Thread edlinger at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

--- Comment #8 from Bernd Edlinger  ---
Author: edlinger
Date: Sat Nov 23 06:33:59 2019
New Revision: 278639

URL: https://gcc.gnu.org/viewcvs?rev=278639=gcc=rev
Log:
PR c++/92365

2019-11-22  Bernd Edlinger  

PR c++/92365
* name-lookup.c (check_local_shadow): Use can_convert_arg
instead of can_convert.

testsuite:
2019-11-22  Bernd Edlinger  

PR c++/92365
* g++.dg/pr92365.C: New test.


Added:
trunk/gcc/testsuite/g++.dg/pr92365.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/name-lookup.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-20 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

--- Comment #7 from Martin Liška  ---
Just for the record, I see the failure in spatialindex package.

[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-07 Thread edlinger at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

--- Comment #6 from Bernd Edlinger  ---
I tried this, and it contradicts what above comment says:

$ cat test1.cc 
void foo()
{
  char *x = int();
}

gcc -Wall -S -std=c++17 test1.cc 
test1.cc: In function ‘void foo()’:
test1.cc:3:9: warning: unused variable ‘x’
[]8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wunused-variable-Wunused-variable]8;;]
3 |   char *x = int();
  | ^

So I would have expected that to be rejected with c++11 and above
and accepted with c++98, but it is accepted with all C++ versions.

BTW: can we get rid of this URL-escapes in the warnings, soon?

[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-07 Thread edlinger at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

--- Comment #5 from Bernd Edlinger  ---
Some insight, why the crash only happens with -std=c++98:

-Wshadow=compatible-local tries to find out if there is an
implicit conversion between the "int16_t f" and "a f".
The only candidate is a::a(char *);
The conversion is only allowed when it f is NULL.

  /* [conv.ptr]
 A null pointer constant can be converted to a pointer type; ... A
 null pointer constant of integral type can be converted to an
 rvalue of type std::nullptr_t. */
  if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
   || NULLPTR_TYPE_P (to))
  && ((expr && null_ptr_cst_p (expr))
  || NULLPTR_TYPE_P (from)))
conv = build_conv (ck_std, to, conv);

and now null_ptr_cst_p is invoked with "int16_t()", aka CAST_EXPR(NULL_TREE):

bool
null_ptr_cst_p (tree t)
{
  tree type = TREE_TYPE (t);

  /* [conv.ptr]

 A null pointer constant is an integer literal ([lex.icon]) with value
 zero or a prvalue of type std::nullptr_t.  */
  if (NULLPTR_TYPE_P (type))
return true;

  if (cxx_dialect >= cxx11)
{
  STRIP_ANY_LOCATION_WRAPPER (t);

  /* Core issue 903 says only literal 0 is a null pointer constant.  */
  if (TREE_CODE (t) == INTEGER_CST
  && !TREE_OVERFLOW (t)
  && TREE_CODE (type) == INTEGER_TYPE
  && integer_zerop (t)
  && !char_type_p (type))
return true;
}
  else if (CP_INTEGRAL_TYPE_P (type))
{
  t = fold_non_dependent_expr (t, tf_none);
  STRIP_NOPS (t);
  if (integer_zerop (t) && !TREE_OVERFLOW (t))
return true;
}

  return false;

and now fold_non_dependent_expr fails.

With above patch we enter with the t = f, the decl we want to cast,
it is obviously not null.

[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-05 Thread bernd.edlinger at hotmail dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

--- Comment #4 from Bernd Edlinger  ---
Created attachment 47180
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47180=edit
possible fix

This seems to fix the issue,
although a fix in cxx_eval_constant_expression
might be preferrable.

[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-05 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek  ---
potential_constant_expression_1 handles CAST_EXPR (and *_CAST_EXPR), but
cxx_evaluate_constant_expression doesn't.
This is on a CAST_EXPR which has NULL first operand created by can_convert:
  /* implicit_conversion only considers user-defined conversions
 if it has an expression for the call argument list.  */
  if (CLASS_TYPE_P (from) || CLASS_TYPE_P (to))
arg = build1 (CAST_EXPR, from, NULL_TREE);
In particular, NULL_TREE is considered to be a potential constant expression
and we fall through into:
  return (RECUR (TREE_OPERAND (t, 0),
 !TYPE_REF_P (TREE_TYPE (t;
in the CAST_EXPR: handling in potential_constant_expression_1, so return true.

[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-05 Thread edlinger at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

--- Comment #2 from Bernd Edlinger  ---
This was a hidden bug:

g++ -std=c++98 -Wshadow=compatible-local test.cc

did ICE all the time.

[Bug c++/92365] [10 Regression] ice unexpected expression ‘int16_t()’ of kind cast_expr

2019-11-04 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92365

Marek Polacek  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-11-04
 CC||mpolacek at gcc dot gnu.org
   Target Milestone|--- |10.0
Summary|ice unexpected expression   |[10 Regression] ice
   |‘int16_t()’ of kind |unexpected expression
   |cast_expr   |‘int16_t()’ of kind
   ||cast_expr
 Ever confirmed|0   |1

--- Comment #1 from Marek Polacek  ---
Started with r277643.