aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2017-09-15 17:21:50 +0000
committerBernd Edlinger <edlinger@gcc.gnu.org>2017-09-15 17:21:50 +0000
commit1d9335766d86262f8335d63d99b328bb44543b01 (patch)
tree5e9491b32fa26d79e07318fdf780451f77607b38 /gcc/cp
parent4a8ca690b0b73f4e0bae542fd69a1ee0d9e73126 (diff)
downloadgcc-1d9335766d86262f8335d63d99b328bb44543b01.zip
gcc-1d9335766d86262f8335d63d99b328bb44543b01.tar.gz
gcc-1d9335766d86262f8335d63d99b328bb44543b01.tar.bz2
common.opt (Wcast-align=strict): New warning option.
2017-09-15 Bernd Edlinger <bernd.edlinger@hotmail.de> * common.opt (Wcast-align=strict): New warning option. * doc/invoke.texi: Document -Wcast-align=strict. c: 2017-09-15 Bernd Edlinger <bernd.edlinger@hotmail.de> * c-typeck.c (build_c_cast): Implement -Wcast-align=strict. cp: 2017-09-15 Bernd Edlinger <bernd.edlinger@hotmail.de> * typeck.c (build_reinterpret_cast_1, build_const_cast_1): Implement -Wcast-align=strict. testsuite: 2017-09-15 Bernd Edlinger <bernd.edlinger@hotmail.de> * c-c++-common/Wcast-align.c: New test. From-SVN: r252832
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/typeck.c17
2 files changed, 18 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0a3b80f..c013225 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-15 Bernd Edlinger <bernd.edlinger@hotmail.de>
+
+ * typeck.c (build_reinterpret_cast_1,
+ build_const_cast_1): Implement -Wcast-align=strict.
+
2017-09-15 Jakub Jelinek <jakub@redhat.com>
* decl.c (redeclaration_error_message): Use cxx17 instead of cxx1z,
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index aa5d128..028d56f 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -7265,15 +7265,16 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
complain))
return error_mark_node;
/* Warn about possible alignment problems. */
- if (STRICT_ALIGNMENT && warn_cast_align
- && (complain & tf_warning)
+ if ((STRICT_ALIGNMENT || warn_cast_align == 2)
+ && (complain & tf_warning)
&& !VOID_TYPE_P (type)
&& TREE_CODE (TREE_TYPE (intype)) != FUNCTION_TYPE
&& COMPLETE_TYPE_P (TREE_TYPE (type))
&& COMPLETE_TYPE_P (TREE_TYPE (intype))
- && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (intype)))
+ && min_align_of_type (TREE_TYPE (type))
+ > min_align_of_type (TREE_TYPE (intype)))
warning (OPT_Wcast_align, "cast from %qH to %qI "
- "increases required alignment of target type", intype, type);
+ "increases required alignment of target type", intype, type);
/* We need to strip nops here, because the front end likes to
create (int *)&a for array-to-pointer decay, instead of &a[0]. */
@@ -7447,6 +7448,14 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain,
the user is making a potentially unsafe cast. */
check_for_casting_away_constness (src_type, dst_type,
CAST_EXPR, complain);
+ /* ??? comp_ptr_ttypes_const ignores TYPE_ALIGN. */
+ if ((STRICT_ALIGNMENT || warn_cast_align == 2)
+ && (complain & tf_warning)
+ && min_align_of_type (TREE_TYPE (dst_type))
+ > min_align_of_type (TREE_TYPE (src_type)))
+ warning (OPT_Wcast_align, "cast from %qH to %qI "
+ "increases required alignment of target type",
+ src_type, dst_type);
}
if (reference_type)
{