Commit cf015ca2 by Thomas Koenig

re PR fortran/82743 (uncaught character truncation in derived type initialization)

2019-01-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/82743
	* primary.c (gfc_convert_to_structure_constructor): If a character
	in a constructor is too long, add a warning with
	-Wcharacter-truncation.

2019-01-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/82743
	* gfortran.dg/structure_constructor_16.f90: New test.

From-SVN: r267499
parent 730832cd
2019-01-01 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/82743
* primary.c (gfc_convert_to_structure_constructor): If a character
in a constructor is too long, add a warning with
-Wcharacter-truncation.
2019-01-01 Jakub Jelinek <jakub@redhat.com> 2019-01-01 Jakub Jelinek <jakub@redhat.com>
Update copyright years. Update copyright years.
......
...@@ -3074,6 +3074,12 @@ gfc_convert_to_structure_constructor (gfc_expr *e, gfc_symbol *sym, gfc_expr **c ...@@ -3074,6 +3074,12 @@ gfc_convert_to_structure_constructor (gfc_expr *e, gfc_symbol *sym, gfc_expr **c
actual->expr->value.character.length = c; actual->expr->value.character.length = c;
actual->expr->value.character.string = dest; actual->expr->value.character.string = dest;
if (warn_line_truncation && c < e)
gfc_warning_now (OPT_Wcharacter_truncation,
"CHARACTER expression will be truncated "
"in constructor (%ld/%ld) at %L", (long int) c,
(long int) e, &actual->expr->where);
} }
} }
......
2019-01-01 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/82743
* gfortran.dg/structure_constructor_16.f90: New test.
2019-01-01 Jan Hubicka <hubicka@ucw.cz> 2019-01-01 Jan Hubicka <hubicka@ucw.cz>
* g++.dg/ipa/devirt-36.C: Add dg-do-compile. * g++.dg/ipa/devirt-36.C: Add dg-do-compile.
......
! { dg-do compile }
! { dg-additional-options "-Wcharacter-truncation" }
! PR 82743 - warnings were missing on truncation of structure
! constructors.
! Original test case by Simon Klüpfel
PROGRAM TEST
TYPE A
CHARACTER(LEN=1) :: C
END TYPE A
TYPE(A) :: A1
A1=A("123") ! { dg-warning "CHARACTER expression will be truncated" }
A1=A(C="123") ! { dg-warning "CHARACTER expression will be truncated" }
A1%C="123" ! { dg-warning "CHARACTER expression will be truncated" }
END PROGRAM TEST
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment